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 to the CF scene
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    form validate before submit to email

    alright so i am trying to validate this form and if you do not fill out the Day of the week then it does not submit the form to email....


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Guest List Signup</title>
    <style type="text/css">
    <!--
    body,td,th {
    	color: #FFF;
    }
    body {
    	background-color: #000;
    }
    -->
    </style></head>
    <script type='text/javascript'>
    function madeSelection(elem, helperMsg){
    	if(elem.value == "Select"){
    		alert(helperMsg);
    		elem.focus();
    		return false;
    	}else{
    		return true;
    	}
    }
    </script>
    
    <body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
    <form name="halo-gl" form method="POST" action="contactgl.php">
      <p>If you want to have your name on the HALO guest list please fill out the form below before 9pm and you and your guests will be on the list at the door.
      <p>This will get you free entry* until 11:30pm (this means at 11:31pm the list is over) also on select events there will not be a list and we might not have it posted on the website.
      <p>Guest list does not guarantee entry. It is to the discression of Halo on wether someone is permitted or not.
      <p>
      <p>Your Name:<br>
        <input type="text" name="MyName">
        (First and Last)
      <p>How Many People I Will Have:<br>
    <select name="HowManyPeopleIWillHave">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
      <p>What day to be on the list:<br>
    <select id='selection'>
    <option value="Select">Please Select</option>
    <option value="Wednesday">Wednesday</option>
    <option value="Thursday">Thursday</option>
    <option value="Friday">Friday</option>
    <option value="Saturday">Saturday</option>
    </select>
    <p><input type="submit" name="submit" value='Submit' onclick="madeSelection(document.getElementById('selection'), 'Please Choose Something')" >
    </form>
    <p>
    
    
    </body>
    </html>


    you can see this currently in action at

    http://www.haloclt.com/guestlist.html


    any help would be appreciated thank you

  • #2
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Code:
    <input type="submit" name="submit" value='Submit' onclick="return madeSelection(document.getElementById('selection'), 'Please Choose Something');" />
    Also your <script> tag must either be in <head> or <body>, you have it in-between them.

  • Users who have thanked Dean440 for this post:

    woody2376 (06-10-2010)

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    dean thanks a lot thats what i was missing now to see why when its not emailing me the day you select what someone selects it

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok let me show the backend of the script


    Code:
    <?php
    
    // get posted data into local variables
    $EmailFrom = "Website Guest-List";
    $EmailTo = "woodysmcshop@gmail.com";
    $Subject = "Guest List Me Please";
    $MyName = Trim(stripslashes($_POST['MyName'])); 
    $HowManyPeopleIWillHave = Trim(stripslashes($_POST['HowManyPeopleIWillHave']));
    $selection = Trim(stripslashes($_POST['selection']));
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    // prepare email body text
    $Body = "";
    $Body .= "My Name: ";
    $Body .= $MyName;
    $Body .= "\n";
    $Body .= "How Many People I Will Have: ";
    $Body .= $HowManyPeopleIWillHave;
    $Body .= "\n";
    $Body .= "Day of the week: ";
    $Body .= $selection;
    $Body .= "\n";
    
    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>

    now when i change


    Code:
    <select id='selection'>
    <option value="Select">Please Select</option>
    <option value="Wednesday">Wednesday</option>
    <option value="Thursday">Thursday</option>
    <option value="Friday">Friday</option>
    <option value="Saturday">Saturday</option>
    </select>
    <p><input type="submit" name="submit" value='Submit' onclick="return madeSelection(document.getElementById('selection'), 'Please Choose a Day!');" />

    the
    Code:
    <select id='selection'>
    to <select name='selection'> then it will send me the day of the week that you choose but it will not have the alert pop up so you can select nothing and it will go through .... but if you have the select id= it will alert you until you select a actual day but when it emails to me it will not have the day at all...

    look like this

    My Name: test
    How Many People I Will Have: 1
    Day of the week:


    oppose to

    My Name: test
    How Many People I Will Have: 1
    Day of the week: Wednesday

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by woody2376 View Post
    dean thanks a lot thats what i was missing now to see why when its not emailing me the day you select what someone selects it
    Your Javascript only says something about the "What Day" part. You probably want to give the Name and the How Many People fields their own IDs so you can just use getElementById() to grab them and work with them.

    Also, to make the form smart, you should use the Date object to see what time it is and make decisions about processing based on that since this seems to be time-sensitive.

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by woody2376 View Post
    the
    Code:
    <select id='selection'>
    to <select name='selection'> then it will send me the day of the week that you choose but it will not have the alert pop up so you can select nothing and it will go through .... but if you have the select id= it will alert you until you select a actual day but when it emails to me it will not have the day at all...
    The solution is to have both the name and the id in there.
    <select id="selection" name="selection">

    With Javascript, it's often desired to use IDs because it gives you a guaranteed correct means of grabbing an element off the page (using getElementById). However, $_POST and $_GET variables in PHP come from the name attribute.

    By having both the id and the name, you're allowing Javascript easy access to the data so it can validate it, and then you can send that same data off to the PHP script in a way that can be accessed with $_POST or $_GET.

    Also, your validation section in the PHP script does nothing.
    PHP Code:
    // validation
    $validationOK=true;
    if (!
    $validationOK) { //This block will never be executed.
      
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;

    Last edited by Dean440; 06-10-2010 at 07:11 AM.

  • #7
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    not following to much...

    as far as for time sensitive well its all depending on what day they would like to come. it could be thursday and they are coming next wednesday

  • #8
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    still learning both php and java thanks a lot Dean

  • #9
    Regular Coder
    Join Date
    Dec 2009
    Posts
    115
    Thanks
    2
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by woody2376 View Post
    not following to much...

    as far as for time sensitive well its all depending on what day they would like to come. it could be thursday and they are coming next wednesday
    Change
    Code:
    <select id="selection">
    to
    Code:
    <select id="selection" name="selection">
    and it should work fine.

    And you can use the Date object to create a date in the future (like next Wednesday at 11:30pm) I'm not sure exactly what you're going for with this page, but that may be useful to you. I noticed that when you submit the form, the page says

    Code:
    "Thank you for your Submission as long as you entered this before 9pm we will have your name at the door. There is no guarantee if you submitted after. SORRY!"
    To make that smarter, you can use the Date object to get the user's time before they submit the form. This way, you can check to see if it's before 9pm. If it's not, you can simply have a popup alert them that they need to come back tomorrow.


  •  

    Posting Permissions

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