SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    port perry, ontario
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form validation not working

    I've got 2 issues happening. I'm not able to validate a selection from a dropdown box. Even when I throw in the towel and remove the validation for that field, the form still won't submit and I'm not getting an error message to show me why. My Javascript is not that strong and I don't know what else to try. If you need to see the live version go to www.owascorv.com/rental_quote2.php

    Condensed code here.

    <form name="quoteform" method="post" action="http://production.threewisemen.ca/cms/action/contact/sendemail">
    <input type="hidden" name="recipient" value="sandi@cmswebsolutions.com" />
    <input type="hidden" name="subject" value="Rental Info Request Form" />
    <input type="hidden" name="sender" value="Owasco RV website <rentals@owasco.com>" />
    <input type="hidden" name="siteid" value="10K-JJ" />
    <input type="hidden" name="redirect" value="http://www.owascorv.com/thankyou.php" />

    <p>*Your Name<br />
    <input type="text" name="Name" size="50"><br />
    *Email Address<br />
    <input type="text" name="email" size="20"><br />
    *Planned Holiday Start Date<br />
    <input type="text" name="Holidaystart" size="50"><br />
    *Planned Holiday End Date<br />
    <input type="text" name="Holidayend" size="50"><br />
    <p>*Please select your preferred Rental RV Transportation from the following list.<br />
    <select name="PreferredRV" size="1">
    <option>10' Truck Camper</option>
    <option>Roadtrek 170</option>
    <option>Roadtrek 190</option>
    <option>Motorhome C-22</option>
    <option>Motorhome C-24</option>
    <option>Motorhome C-28</option>
    <option>30' Luxury Motorhome</option>
    </select></p>

    <p><input type="button" value="Submit" class="submit" onclick="return finalCheck(this.form)">&nbsp;<input type="reset" value="Reset" class="submit"></p>
    </form>

    <script language="JavaScript"><!--

    function finalCheck(form) {
    // final check of entries' validity

    if (form.Name.value == '') {
    alert("Please provide your name.");
    form.Name.focus();
    return false;
    }

    if (form.email.value == '') {
    alert("Please provide your email address.");
    form.email.focus();
    return false;

    }

    if (form.Holidaystart.value == '') {
    alert("Please tell us when your holiday begins.");
    form.Holidaystart.focus();
    return false;

    }

    if (form.Holidayend.value == '') {
    alert("Please tell us when your holiday ends.");
    form.Holidayend.focus();
    return false;

    }

    RVChoice = form.PreferredRV.selectedIndex;
    if(form.PreferredRV.options[RVChoice].value=="") {
    alert("Please tell us which vehicle you prefer.");
    form.PreferredRV.focus();
    return false;

    }

    if (!isValidEmail(form, form.email, form.email.value)) {
    return false;

    }

    else
    return true;
    form.submit();
    }

    function isValidEmail(frm,fld,entry) {
    var re = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
    if (!re.test(entry)) {
    alert("The email address you entered doesn't appear to be valid.")
    if (document.forms[frm.name]) { // protect ns4 in case of nesting
    setTimeout("setFocus(document.forms['"+frm.name+"'].elements['"+fld.name+"'])",100);
    } else {
    fld.focus(); fld.select();
    }
    return false;
    } else return true;
    }

    //--></script>

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, for ease-of-use:

    Code:
    <form name="quoteform" method="post" action="http://production.threewisemen.ca/cms/action/contact/sendemail">
    <input type="hidden" name="recipient" value="sandi@cmswebsolutions.com" />
    <input type="hidden" name="subject" value="Rental Info Request Form" />
    <input type="hidden" name="sender" value="Owasco RV website <rentals@owasco.com>" />
    <input type="hidden" name="siteid" value="10K-JJ" />
    <input type="hidden" name="redirect" value="http://www.owascorv.com/thankyou.php" />
    
    <p>*Your Name<br />
    <input type="text" name="Name" size="50"><br />
    *Email Address<br />
    <input type="text" name="email" size="20"><br />
    *Planned Holiday Start Date<br />
    <input type="text" name="Holidaystart" size="50"><br />
    *Planned Holiday End Date<br />
    <input type="text" name="Holidayend" size="50"><br />
    <p>*Please select your preferred Rental RV Transportation from the following list.<br />
    <select name="PreferredRV" size="1">
    <option>10' Truck Camper</option>
    <option>Roadtrek 170</option>
    <option>Roadtrek 190</option>
    <option>Motorhome C-22</option>
    <option>Motorhome C-24</option>
    <option>Motorhome C-28</option>
    <option>30' Luxury Motorhome</option>
    </select></p>
    
    <p><input type="button" value="Submit" class="submit" onclick="return finalCheck(this.form)">&nbsp;<input type="reset" value="Reset" class="submit"></p>
    </form>
    
    <script language="JavaScript"><!--
    
    function finalCheck(form) {
    // final check of entries' validity
    
    if (form.Name.value == '') {
    alert("Please provide your name.");
    form.Name.focus();
    return false;
    }
    
    if (form.email.value == '') {
    alert("Please provide your email address.");
    form.email.focus();
    return false;
    
    }
    
    if (form.Holidaystart.value == '') {
    alert("Please tell us when your holiday begins.");
    form.Holidaystart.focus();
    return false;
    
    }
    
    if (form.Holidayend.value == '') {
    alert("Please tell us when your holiday ends.");
    form.Holidayend.focus();
    return false;
    
    }
    
    RVChoice = form.PreferredRV.selectedIndex;
    if(form.PreferredRV.options[RVChoice].value=="") {
    alert("Please tell us which vehicle you prefer.");
    form.PreferredRV.focus();
    return false;
    
    }
    
    if (!isValidEmail(form, form.email, form.email.value)) {
    return false;
    
    }
    
    else
    return true;
    form.submit();
    }
    
    function isValidEmail(frm,fld,entry) {
    var re = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
    if (!re.test(entry)) {
    alert("The email address you entered doesn't appear to be valid.")
    if (document.forms[frm.name]) { // protect ns4 in case of nesting
    setTimeout("setFocus(document.forms['"+frm.name+"'].elements['"+fld.name+"'])",100);
    } else {
    fld.focus(); fld.select();
    }
    return false;
    } else return true;
    }
    
    //--></script>
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript">
    
    function finalCheck(oForm)
    {
    	var focus_el = null, msg = '';
    	if (isEmpty(oForm.Name))
    	{
    		msg += "~ Please provide your name.\n";
    		focus_el = focus_el || oForm.Name;
    	}
    	if (!isValidEmail(oForm, oForm.email, oForm.email.value))
    	{
    		msg += "~ Please enter a valid email address.\n";
    		focus_el = focus_el || oForm.email;
    	}
    	if (isEmpty(oForm.Holidaystart))
    	{
    		msg += "~ Please tell us when your holiday begins.\n";
    		focus_el = focus_el || oForm.Holidaystart;
    	}
    	if (isEmpty(oForm.Holidayend))
    	{
    		msg += "~ Please tell us when your holiday ends.\n";
    		focus_el = focus_el || oForm.Holidayend;
    	}
    	var RVChoice = oForm.PreferredRV.options[oForm.PreferredRV.selectedIndex];
    	if (RVChoice.value == "")
    	{
    		msg += "~ Please tell us which vehicle you prefer.\n";
    		focus_el = focus_el || oForm.PreferredRV;
    	}
    
    	if (msg != '')
    	{
    		var prefix = "To assist us in processing your form:\n\n";
    		var suffix = "\nKindly correct and resubmit. Thank you.";
    		alert(prefix + msg + suffix);
    		if (focus_el.focus)
    			focus_el.focus();
    		return false;
    	}
    	return true;
    }
    
    function isEmpty(field)
    {
    	return /^\s*$/.test(field.value);
    }
    
    function isValidEmail(frm, fld, entry)
    {
    	var re = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
    	return (re.test(entry));
    }
    
    </script>
    </head>
    <body>
    <form name="quoteform" action="http://production.threewisemen.ca/cms/action/contact/sendemail" method="post" 
    onsubmit="return finalCheck(this)">
    <input type="hidden" name="recipient" value="sandi@cmswebsolutions.com" />
    <input type="hidden" name="subject" value="Rental Info Request Form" />
    <input type="hidden" name="sender" value="Owasco RV website <rentals@owasco.com>" />
    <input type="hidden" name="siteid" value="10K-JJ" />
    <input type="hidden" name="redirect" value="http://www.owascorv.com/thankyou.php" />
    
    <p>*Your Name<br />
    <input type="text" name="Name" size="50"><br />
    *Email Address<br />
    <input type="text" name="email" size="20"><br />
    *Planned Holiday Start Date<br />
    <input type="text" name="Holidaystart" size="50"><br />
    *Planned Holiday End Date<br />
    <input type="text" name="Holidayend" size="50"><br />
    <p>*Please select your preferred Rental RV Transportation from the following list.<br />
    <select name="PreferredRV" size="1">
    <option value="">- choose -</option><!-- edited w/apologies! -->
    <option value="10' Truck Camper">10' Truck Camper</option>
    <option value="Roadtrek 170">Roadtrek 170</option>
    <option value="Roadtrek 190">Roadtrek 190</option>
    <option value="Motorhome C-22">Motorhome C-22</option>
    <option value="Motorhome C-24">Motorhome C-24</option>
    <option value="Motorhome C-28">Motorhome C-28</option>
    <option value="30' Luxury Motorhome">30' Luxury Motorhome</option>
    </select></p>
    <p><input type="submit" value="Submit" class="submit">&nbsp;<input type="reset" value="Reset" class="submit" 
    onclick="return confirm('Clear all entries?')"></p>
    </form>
    </body>
    </html>
    Last edited by adios; Jul 11, 2004 at 18:11.
    ::: certified wild guess :::

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Paris
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also work on form now. Have no problems with validation. Try to "personalize" and declare your form and form.name

    function finalCheck(form) {
    // final check of entries' validity

    var NameProbatio = document.quoteform.Name.value
    var Letterae
    if (NameProbatio.length<1) {
    alert("Please provide your name.");
    NameProbatio.focus()}
    else {
    return true;}}
    }

    The same with all your <input>s u want to verify.
    Avoid Name as <input>'s name.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    port perry, ontario
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    adios, i've tried the script you've provided. nice touches with the extra message window - thanks. however, the RV selection is still not working. is it because it's a dropdown? do i need to use a different form element in order to validate?

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    port perry, ontario
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    success. changed if (RVChoice.value == "") to if (RVChoice.value == "0") and added a form.submit; at the end. thanks for the help.

  7. #7
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    adios', there is a small problem with your code, you should use <option value="">- choose -</option>. Mozilla takes the option's contents as the value if value is not set.


Bookmarks

Posting Permissions

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