Reputation: 65
I am trying to pass newsletter subscribe information (name and email) from an HTML Form to CURLOPT_POSTFIELDS.
My form looks like this:
<form class="form-signin" method="POST" action="URL_TO_POST_TO">
<h2 class="form-signin-heading">Please sign in</h2>
<input class="form-control" type="text" autofocus="" required="" placeholder="Email address">
<input class="form-control" type="name" required="" placeholder="name">
<label class="checkbox">
</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
My PHP Curl looks like:
<?php
$curl = curl_init();
$EMAIL = "Test";
curl_setopt_array($curl, array(
CURLOPT_URL =>
"https://spaces.nexudus.com/api/content/newslettersubscribers",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{\n\"BusinessId\": 469969507}", \n\"Name\",'.
$EMAIL .',\n\\"Email\\": \\'.$EMAIL.'\\"\n"}',
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer
123345345345345345345345345345345",
"Cache-Control: no-cache",
"Content-Type: application/json",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?> I was thinking there might be a way to pass my form into the $EMAIL variable.
Any help with this will be greatly appreciated. Thank you,
Upvotes: 0
Views: 362
Reputation: 15131
You need to add n action to your form:
<form class="form-signin" method="POST" action="path/to/file.php">
Add a "name" attribute to your input:
<input name="email" class="form-control" type="text" autofocus="" required="" placeholder="Email address">
And then, after submit, get on the server (PHP) side:
$EMAIL = $_POST['email'];
Upvotes: 1