SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    validating email form checking for default address

    I am writing a script to validate an email address submission form. The form has a default email address:

    HTML Code:
     <input type="text" name="email_address" onfocus="this.value=''" value="your@email.com" maxlength="255" size="25" />
    In the validation script I want to check that the user has not left this value in the field, but has entered his own email address. I have tried a few things based on the following script, which checks that the email has been correctly entered twice
    HTML Code:
     if (document.form1.email_address.value != document.form1.email_address_verify.value)
    {
    alert("The two e-mail address you entered do not match. Please check and correct. Thank You.");
    return (false);
    }
    Here is the latest thing I have tried, which does not trigger the alert:
    HTML Code:
     if (document.form1.email_address.value = 'your@email.com')
    {
    alert("Please enter your own email address. Thank You.");
    return (false);
    }
    I also tried it with double quotes and no quotes.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have a logical mistake:
    Code:
    if (document.form1.email_address.value == 'your@email.com')
    Saul

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally I think you should use a label instead of pre-filling the field. Pre-filled fields (with useless data) are nothing but annoying.

    HTML Code:
    <label for="iemail_address">You e-mail address:</label> <input type="text" name="email_address" id="iemail_address" maxlength="255" size="25" />
    Well anyway.

    Code:
    if (document.form1.email_address.value != document.form1.email_address_verify.value)
    Sorry but I find it funny as hell

    You should know that text fields have a defaultValue property as well. You could check it against the value.

    Code:
    if (document.form1.email_address.value = 'your@email.com')
    Doesn't work because you are using = instead of ==.

  4. #4
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  5. #5
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,383
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I decided to go with the label idea instead of pre-filling the field. However, the script I am using does not check that the address entered into the email validation field matches the address in the first email field. What am I missing? Here is the script:

    HTML Code:
     <!-- fom validation script -->
    <script language="JavaScript">
    <!--
    var reWhitespace = /^\s+$/;
    function isEmpty (s) { 
    return ((s == null) || (s.length == 0) || reWhitespace.test(s));
    }
     
    function ValidateDetails() {
    if (isEmpty(document.form1.email_address.value) ||
    (document.form1.state.selectedIndex == 0)) {
    alert("Please provide us with your request details");
    return(false);
    }
     
    if (document.form1.email_address.value != document.form1.email_address_verify.value)
    {
    alert("The two e-mail addresses you entered do not match. Please check and correct. Thank You.");
    return (false);
    }
     
    // All conditions satisfied. Time to submit the form.
    document.form1.submit();
    }
    // -->
    </script>
    <!-- End form validation script -->
    <?php 
    //echo "<p>First Name: " .$ctlg_firstname. "</p>";
    //echo "<p>Last Name: " .$ctlg_lastname. "</p>";
    ?>
     
    <p>Stay inspired. Sign up for Kripaluís e-mail list and receive information about programs and special events, as well as our monthly newletter, Kripalu Online. Donít worry, we donít send a lot, just enough to stay connected.</p>
    <form name="form1" method="post" action="ctlg_order_addl_info.php" onSubmit="ValidateDetails();return false">
    <!-- Email signup table -->
    <table cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td align="right" valign="top">
    	 <p><label>Your E-mail Accress:</label></p>
    <td colspan="3" valign="top"> 
    	 <p><input type="text" name="email_address" id="email_address" maxlength="255" size="25" /></p>
    </tr>
    <tr> 
    <td align="right" valign="top">
    	 <p><label>Please confirm your E-mail Accress:</label></p>
    <td colspan="3" valign="top"> 
    	 <p><input type="text" name="email_address_verify" id="email_address_verify" maxlength="255" size="25" /></p>
     
    <input type="hidden" name="first_name" value="<?php echo $ctlg_firstname; ?>" />
    <input type="hidden" name="last_name" value="<?php echo $ctlg_lastname; ?>" />
    <br /><input type="submit" value="Submit" name="submit"></p>
    </td>
    </tr>
    </table>
    </form>
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dont forget to check the format of the email..
    Code:
    document.form1.email_address.match(/^w*?\@w*?\.(w{2,3}|w{2,3}\.w{2,3})$/i)
    cheers


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
  •