Form in the server site contains one text box and two radio buttons and a submit button. This is waht I tried. Please help.
$url = "Url goes here";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"postcode\":\"3150\", \"customerType\":\"Residential\",\"fuelType\":\"Electricity\"}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
echo "test";
}
echo "<pre>";
print_r($result);
echo "</pre>";
curl_close($ch);
}
?>
It works like for a text value.
Find the name of these radio, check the value you want.
Example :
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
Your cURL Postfield should looks like this :
$data = array('gender' => 'male');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);