Jump to content

Forms - submit


trampolinejoe

Recommended Posts

Heya everyone,

 

I need a hand, I got a form submitting and my alert is being made when a feild is not filled correctly.

But the form still submits and i do not want it to submit.

 

 

 

 

Below is the header:

 

function validate_form ( )
{
    valid = true;

    if ( document.form1.name.value == "" ||
     document.form1.address.value == "" ||
	 document.form1.zip.value == "" ||
	 document.form1.lastname.value == "" ||
	 document.form1.homenumber.value == "" )
    {
        alert ( "Please fill out all the required fields" );
        valid = false;

    }

    if ( document.form1.email.value != document.form1.emailconfirm.value )
    {
        alert ( "Your email did not match your confirm email." );
        valid = false;

    }

    if (is_nan(document.form1.zip.value) == true)
    {
        alert ( "You must use real numbers in your post code.." );
        valid = false;

    }

if(document.form1.terms.checked){
    alert ( "You must agree to our terms and conditions to contine.");
    valid = false;

}

    return valid;
}

 

 

Below is the heading for my form:

 <form name="form1" method="post" onSubmit="javascript: return validate_form();" action="backend/processingPayment.php">
....

 

Thanks Guys,

 

Link to comment
https://forums.phpfreaks.com/topic/113062-forms-submit/
Share on other sites

This isn't PHP related however, I use this function to stop a form from being submitted.

 

<script type="text/javascript">

/*
Block multiple form submission script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact for use
*/

//Enter error message to display if submit button has been pressed multiple times below.
//Delete below line if you don't want a message displayed:

var formerrormsg="You\'ve attempted to submit the form multiple times.\n Please reload page if you need to press button again."

function checksubmit(submitbtn){
submitbtn.form.submit()
checksubmit=blocksubmit
return false
}

function blocksubmit(){
if (typeof formerrormsg!="undefined")
alert(formerrormsg)
return false
}

</script>

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/113062-forms-submit/#findComment-580752
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.