Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Call 2 funtions onSubmit

    Hello, new to the forum. I searched for this and found one relevant thread, but their solution did not work for me.

    I am calling 2 functions onSubmit in a form. One check to make sure all fields are filled in, the other checks that the email address syntax is correct. If i call one or the other of these funtions, the form seems to work.

    However calling both function in the onSubmit doesn't work. Here's the test page:

    http://www.clubspaces.com/signuptest.htm

    First I tried this :

    Code:
    onsubmit="return (emailCheck(this.email.value) && validate_form())"
    but all that would happen is the form fields would get cleared when you click the submit button.

    I also tried writing a new function that checks for false from both the original functions:

    Code:
    function OnSubmitCheck() {
    var one = emailCheck(this.email.value);
    var two = validate_form(); 
    if((one == false) || (two == false)) { 
    return false; 
    }
    return true;
    }
    with this in the form:

    Code:
    onSubmit="OnSubmitCheck()"
    This also did not work, and again clears the form without submitting it. It SHOULD go to a thank-you page after submitting and the redirect isn't working. Can any one help sort this out? Here is the code for the 2 original fucntions I am trying to call:

    Code:
    function emailCheck(emailStr) {
    
    // checks if the e-mail address is valid
    var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
    var matchArray = emailStr.match(emailPat);
    if (matchArray == null) {
    alert("Your email address seems incorrect.  Please try again (check the '@' and '.'s in the email address)");
    return false;
    }
    // make sure the IP address domain is valid
    var IPArray = matchArray[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
    if (IPArray != null) {
    for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
    alert("Your email destination IP address is invalid!");
    return false;
          }
       }
    }
    return true;
    }
    
    function validate_form() {
    
    var message="Please complete the following: \n------------------------------------------------\n";
    var noerrors=message;
    
    if (document.getElementById('template').value == "") {
    	message=message + "Please choose a template for your site! \n";
    }
    if (document.getElementById('clubtype').value == "") {
    	message=message + "Please tell us what type of club you have! \n";
    }
    if (document.signup.company.value == "") {
    	message=message + "Please choose a name for your club! \n";
    }
    if (document.signup.first_name.value == "") {
    	message=message + "Please fill in your first name! \n";
    }
    if (document.signup.last_name.value == "") {
    	message=message + "Please fill in your last name! \n";
    }
    if (document.signup.email.value == "") {
    	message=message + "You must provide us with an email address! \n";
    }
    if (document.signup.phone.value == "") {
    	message=message + "Please fill in your phone number! \n";
    }
    if (document.signup.city.value == "") {
    	message=message + "Please fill in your city of residence! \n";
    }
    if (document.signup.state.value == "") {
    	message=message + "Please fill in your state of residence! \n";
    }
    if (document.signup.country.value == "") {
    	message=message + "Please fill in your country of residence! \n";
    }
    if (document.getElementById('numbers').value == "") {
    	message=message + "Please fill in the number of members you have! \n";
    }
    if (document.getElementById('refer').value == "") {
    	message=message + "Please tell us how you found us! \n";
    }
    if (!document.signup.tac.checked){
    	message=message + "You must agree to the Terms and Conditions before proceeding! \n";
    } 
    if(message==noerrors){
    return true;	
    }
    else{
    alert(message);	
    return false;
    }
    }

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Hi shiftless,

    Maybe a silly question as I have not looked at the details, but shouldn't there be something in your action attribute. Usually this would be the script that handles form submission?
    Code:
    <form name="signup" method="post" action="#" onsubmit="OnSubmitCheck(); return false">

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, i took the action out so i would not inundate my client with test emails. i was wondering if not having an action had any effect on the process. I would think that the redirect page would come up even if the action wasn't going anywhere if it were working properly. anyone?

  • #4
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    It won't. A redirect will have to be handled by the script.

    Actually your script seem to be working. When you submit the form the page reloads. Notice the # appended to the url in your browsers address line. Because this is the action you specified.

    Recall that the page in the action attribute may be any page. It is just tells you the page that is loaded after form submission (just a kind of advanced link), but with the ability to hold post data.

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm... this page worked fine when i was only using the script that checks for blank fields. I have a hidden input for the redirect in the form, and that worked fine at that point:
    Code:
    <input type="hidden" value="http://www.clubspaces.com/welcome.htm" name="redirect" />
    it's just when i tried incorporating this new email syntax function, the redirect stopped working.

    the action sent the post data to a 3rd party service and was not the page that loaded after the form was submitted.

  • #6
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    The hidden field merely passes the information about which page the server-side script should redirect you to after it has finished its job handling the data.

    Therefore it is still necessary to have the action tag. I think you have misunderstood what forms are doing. For fun you may try to put the redirect page directly into your action tag
    Code:
    <form name="signup" method="post" action="http://www.clubspaces.com/welcome.htm" onsubmit="return (emailCheck(this.email.value) && validate_form())">
    It will then look right what is going on seen from the user, but all form handling is bypassed, and the form would be useless.

  • #7
    New Coder
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I added the action back in to test and see if it would send back the redirect, and it didn't work, it just cleared the form. damn this is frustrating...

    maybe i should put the redirect in the function?

  • #8
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Alright, there is nothing wrong with your javascript validation.

    Where did you get the instructions about what hidden fields to use (names and values)? Try to double check the instructions. It is probably here the problem lies.

  • #9
    New Coder
    Join Date
    Jan 2007
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK I have figured it out ( I think). I had at one point changed the hidden input to "redirect" as an experiement, and the 3rd party service requires it to be "retURL" so it's server didn't recognize the info when it was posted. I changed it back and all is working well now. Thanks so much for the help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •