...

View Full Version : Switch form action after php validation



ProTek2
10-07-2011, 04:54 PM
I need for the submission of an unvalidated from to reload the page to allow for php validation which, if passed, would use javascript to change the form's action to an external site.

First, is the following approach sound?

<script type="text/javascript">
if(my_php_validation_ok == true)
document.form.action="the_external_url"
else
document.form.action="current_page.php"
</script>


Second, how should the <form> action be styled to accomplish this?

Philip M
10-07-2011, 06:25 PM
That ought to work :)
Assumes that my_php_validation_ok is passed from PHP.

Not sure what you mean by "how should the <form> action be styled to accomplish this?". Presumably the validation is invoked with a submit button.

Something like this:-


<script type = "text/javascript">

function OnSubmitForm() {
if(my_php_validation_ok) {
document.myform.action="the_external_url";
}
else {
document.myform.action="current_page.php";
}
alert (document.myform.action); // for testing
}
</script>


<form name="myform" onSubmit="return OnSubmitForm();">
<input type = "submit" name = "submitButton" value = "Submit">
</form>


Quizmaster: King Edward VIII abdicated the throne in order to marry whom?
Contestant: Anne Boleyn

ProTek2
10-09-2011, 12:16 AM
The following line of your answer was the second part of what I was asking:

<form name="myform" onSubmit="return OnSubmitForm();">


Thank you for your assistance.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum