This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Validate Form?

  • Creator
    Topic
  • #2096
    mattvd
    Member

    Hi there, we want to have a javascript snipet to validate our form here:

    http://ugly.thirstyagent.com/webinar

    I have the code at:

    function validateForm()
    {
    var a=document.forms["myform"]["inf_field_FirstName"].value;
    var b=document.forms["myform"]["inf_field_Email"].value;
    var c=document.forms["myform"]["inf_field_Phone1"].value;
    if (a==null || a=="" || a=="First Name Here")
    {
    alert("Please enter your First Name!");
    return false;
    }
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.myform.inf_field_Email.value.search(emailRegEx) == -1)
    {
    alert("Please enter a valid email address.");
    return false;
    }

    if (c==null || c=="" || c=="Enter Your Phone Here")
    {
    alert("Please enter your Phone Number!");
    return false;
    }

    and the code doesn’t seem to be validating the form – it goes to an ugly page after to validate rather than keep the user inside the site to validate. Any help is appreciated

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #2109
    Jason Bobich
    Keymaster

    I’d look at how you’re putting in that javascript into that page. Maybe consider actually enqueing it in a JS file or at least wrapping it in the [raw] shortcode so WordPress doesn’t stick all the

    tags throughout.

    I’d think that would have something to do with it.

    #2131
    mattvd
    Member

    Thank you very much, the [raw] shortcode fixed wordpress automatic formatting so that the validation works now

    #2141
    Jason Bobich
    Keymaster

    Oh perfect. That was easier than expected.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The forum ‘Alyeska Responsive WordPress Theme’ is closed to new topics and replies.