views:

182

answers:

2

hello

i use of php and jquery in my application

i want when users submit success a form in page1 , forward form page1 to page2 and show a pop-up message(like this site) "success" and when they do not submit success , dont forward and just show pop-up message "error"

how i can implement this process?

thanks?

A: 

You would use something like this:

<?
if($form_success) { //
   header("location: formpage2.php?success=1");
}
else {
   header("location: formpage1.php?error=1");
}
?>

If you wanted to pass form data from page1 to page2 on success, use either or URL query string or store whatever's in $_POST in $_SESSION.

For the popup message, I would check for a success value in the query string of formpage2 and from there use javascripts alert to alert the user of their success.

Levi Hackwith
A: 

In your form, you can add some javascript into your form tag like so...

<form action="page2.php" onsubmit="if (CONDITION) {alert('Success'); return true;} else { alert('Error'); return false;}">
    <input type="submit" value="Submit">
</form>

You can just a call a function ("return checkCondition();") in the onsubmit part and write the function in a separate Javascript file.

If the Javascript in the onsubmit part returns true, then it will go to the page specified in the action. If it returns false, then the form validation fails and it will stay where it is.

muddybruin