treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Form validation & Submission

  • hey everyone,

    I have a form script in PHP and it works well, but it does not validate the HTML Fields.

    I found on a site a javascript validation, it works well in test mode, which is before it is sent to the PHP script to email.

    I have the script starting like this for testing the javascript validator:
    <form name=\"demo\" onsubmit=\"return validateFormOnSubmit(this)\" action=\"\">


    without the validation I normally let the srcipt work.
    <form method=\"post\" action=\"contact.php\">


    How can I get the validation to work and when it is all valid, it automatically posts to the contact php?

    within the javascript I have this piece of code:

    if (reason != \"\") {
    alert(\"Some fields need correction:\n\" + reason);
    return false;
    }

    alert(\"All fields are filled correctly\"); //this is the part that says everything is done correctly
    return false;
    }
  • I got it to work.....

    I stupidly did not return it as true.

    it now works very well, now to implement it to my clients.