Jump to content

Send form data after Javascript check


kurt.santo

Recommended Posts

I have a language specific contact page, which is included into contact.php. I test for valid entries via Javascript and have just a test in php to see if form is submitted and if yes the email the $_POST values. It does not work, neither does it send the email nor does it transfer to contact2.php. The relevant code is:

if (isset($_POST['submitted'])){		$S = '';		foreach($_POST as $key=>$value){  			$S.= $key ." : ". $value."\n";			}		mail('info@domain.co.uk','Web Formular', $S);       header ("Location: contact2.php");}$page_content = <<<EOT<form action="contact.php" method="post" onSubmit="return Validator(this);">...form content here

When I had an error array with all checks via PHP it worked well (used on different website). Would I have to amend the foreach bit? Or is it a problem to have the onSubmit JavaScript bit?Kurt

Link to comment
Share on other sites

The PHP bit looks fine. Is your form being submitted at all? Also, make sure you have an input (it could be the submit button) with name="submitted".

Link to comment
Share on other sites

The PHP bit looks fine. Is your form being submitted at all? Also, make sure you have an input (it could be the submit button) with name="submitted".
The name in the submit button was the cause, it was submit and not submitted. Works now, cheers!Do you know any change how to amend:
		$S = '';		foreach($_POST as $key=>$value){  			$S.= $key ." : ". $value."\n";			}

So, that first and last input do not get send (first is the three required fields and last the submit button).Kurt

Link to comment
Share on other sites

You can check the key to make sure it is not one you don't want

foreach($_POST as $key=>$value){if ($key != "submitted" && $key != "firstfieldname") $S.= $key ." : ". $value."\n";}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...