Action form in javascript

Hi, I have setup a basic enquiry form with a Captcha - once the code has been inserted and is correct I want to action the form (submit). I have been advised that javascript is a good method for this.

<?php

session_start();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	$vResult = '';
	if(strtolower($_SESSION['security_code']) != strtolower($_POST['security_code'])){
		$vResult = 'Invalid code!';
	}
	else{
		"/enquiry.php"
	}
}
?>

I want to submit the form to /enquiry.php - I tried header(Location… and realised that just redirects, and doesn’t submit the form.

Any suggestions or tips would be great.

Note, the above script is loaded before the page so that code is above the <html><body>

Cheers,

Paul

2 options you have are

  1. in enquiry.php, check the captcha value the user entered. If it is correct, continue executing enquiry.php or else redirect back to the form page.

  2. in the form page, have an onsubmit event handler that sends a synchronous ajax request to the server to check the captcha value. If the ajax response says the value is correct, the event handler should return true (which then allows the form to be submited) or else return false which will stop the form from being submitted.