Using PHP to POST - How to Inculde Form ID

I’m using PHP’s stream_context_create() to post data. Everything is working great no problems. See current form below.

Now, I need to be able to include the original HTML Form’s ID, but I have no clue how.

The HTML version of this form has the following form tag:

<form method="post" action="http://www.acceptmydata.com/form.php?form=1" id="frmFF1">

I need to include/send: id=“frmFF1”

How would you add id=“frmFF1” to the script below?

$url = "http://www.acceptmydata.com/form.php?form=1";

$data = http_build_query(
	array(
		'NameFirst' => $first_name,
		'NameLast' => $last_name,
		'email' => $email
	)
);

$optional_headers = null;

$params = array('http' => array(
	'method' => 'POST',
	'content' => $data
));
if ($optional_headers !== null) {
	$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
	throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
	throw new Exception("Problem reading data from $url, $php_errormsg");
}

Any help would be greatly appreciated!

You can’t do it with the form’s id. You need to add a hidden input with the same value and use that.

Probably the simplest way would be to add the id value to a hidden input value in your form, then just retrieve with your other $_POST values.

WOW! 2 replies within 4 minutes!

Thanks, I’ll give it a try…

<input type=“hidden” name=“formid” id=“formid” value=“frmFF1”>

If your not to sure :stuck_out_tongue: