View Full Version : Switch form action after php validation

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)

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) {
else {
alert (document.myform.action); // for testing

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

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

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.