Undefined index from a <form> post

Hi,

I have a form on ‘contact.php’ which posts to ‘thankyou.php’ page that contains a function to capture the form ouput and write to a file. I can’t see any thing wrong with the syntax but I get a ‘Notice: Undefined index: txt_email in C:\wamp\www\o2aaic\smartsteps\ hankyou.php on line 86’ error. I can test if its set to stop the error but I can’t see what I’ve missed to actually pull in the post request.


<form name="tenderForm" action="thankyou.php" method="post" id="contactForm" enctype="text/plain" onsubmit="return validate_form();">
    ...
    <input type="text" name="Email" value="" id="txt_email" class="required" />


The php code is:

function appendText() {
	
	$file = "e_address.txt";
	$fh = fopen($file, 'a') or exit("can't open file");

	//Check file is writable and form data is set
	if(is_writable($file) && isset($_POST['txt_email']))
	  {
		$fh = fopen($file, 'a') or exit("can't open file");
		$stringData = $_POST["txt_email"];
		fwrite($fh, $stringData);
		echo "SUCCESS";
		fclose($fh);
	  }
	else
	  {
	// Polite error message to be defined
	  }
}

I’ve not done much php coding recently so I’m a little rusty but any help would be appreciated
Thanks, Des

that error message is telling you that you don’t have an element whose name is txt_email in your form as referenced by your line of code:

$stringData = $_POST[“txt_email”][COLOR=#339933];

[/COLOR]Form data is sent in name/value pairs, not id/value pairs[COLOR=#339933]

[/COLOR]

Thanks, I’ve amended the code now but I still get the same error


<input type="text" name="txt_email" value="" id="txt_email" class="required" />

php is the same.

The function works fine when I just try to append text eg:


$stringData = "TEST\
";

and I have other websites running on the same AMP stack and they process the POST correctly.

any other ideas?

‘Notice: Undefined index: txt_email in C:\wamp\www\o2aaic\smartsteps\ hankyou.php on line 86’

What is the code in line 86?

Its the line that pulls in the POST data:

$stringData = $_POST["txt_email"];

Solved.

The form had an encoding type set, when I remove this it fixes the problem. So for completeness, the form code is now:


<form name="tenderForm" action="thankyou.php" method="post" id="contactForm" onsubmit="return validate_form();">            

rather than

<form name="tenderForm" action="thankyou.php" method="post" id="contactForm" enctype="text/plain" onsubmit="return validate_form();">            

Thanks for your help.