block submission form from submitting.

Discussion in 'PHP' started by caligrafx, Aug 25, 2009.

  1. #1
    I have this code that is not working and can't figure out why. Can someone please help me.


    code
    // are you human?
    if (($human == "yes") {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_thanks.html\">";
    }
    } else {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    } 
    if (empty ($human)) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    Code (markup):
    I just want it to make sure that the type "yes" for the form to be submitted if not then to give them the error page. I have the "empty" working but not the exact work "yes". If they type any thing else other then yes it still goes through and I don't want that.

    Thanks,
    Adam
     
    caligrafx, Aug 25, 2009 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    You do not need the extra empty check. You also have some extra brackets which aren't needed. This should work if your form uses the POST method. If it uses the GET method, just change POST to GET:

    
    // are you human?
    if ($_POST['human'] == "yes") {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_thanks.html\">";
    } else {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    } 
    
    PHP:
     
    ThePHPMaster, Aug 25, 2009 IP
  3. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    oh yeah, that makes sense now!

    That worked like a charm, thanks a million!!!!


    Adam
     
    caligrafx, Aug 25, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    By the way I would recommend actually using Captcha, or better yet reCAPTCHA
     
    kblessinggr, Aug 25, 2009 IP
  5. a53mp

    a53mp Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You should also use PHP header redirects instead of browser meta redirects

    <?php
    if (){header("location:this.php"); exit;}
    else {header("location:that.php"); exit;}
    ?>
     
    a53mp, Aug 25, 2009 IP
  6. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #6
    I have one more problem with this form. When I submit it I do receive everything but the rest of the checked boxes that I select. I receive the last one on the list that I select.

    How would I fix this issue?

    Here is the html
    <td>Music Genres</td>
        <td rowspan="2">&nbsp;</td>
        <td width="131" rowspan="2">
        	<label><input type="Checkbox" name="Genre" Value="All_Types" /> All Types</label><br />
            <label><input type="Checkbox" name="Genre" Value="Various_Types" /> Various Types</label><br />
        	<label><input type="Checkbox" name="Genre" Value="Alternative" /> Alternative</label><br />
        	<label><input type="Checkbox" name="Genre" Value="Ballroom" /> Ballroom</label><br />
            <label><input type="Checkbox" name="Genre" Value="Big_Band" /> Big Band</label><br />
            <label><input type="Checkbox" name="Genre" Value="Blues" /> Blues</label><br />
            <label><input type="Checkbox" name="Genre" Value="Broadway" /> Broadway</label><br />
            <label><input type="Checkbox" name="Genre" Value="Classical" /> Classical</label><br />
            <label><input type="Checkbox" name="Genre" Value="Country" /> Country</label><br />
            <label><input type="Checkbox" name="Genre" Value="Disco" /> Disco</label><br />
            <label><input type="Checkbox" name="Genre" Value="Ethnic" /> Ethnic</label><br />
            <label><input type="Checkbox" name="Genre" Value="Folk" /> Folk</label><br />
            <label><input type="Checkbox" name="Genre" Value="Hip_Hop-Rap" /> Hip Hop/Rap</label><br />
            <label><input type="Checkbox" name="Genre" Value="Irish" /> Irish</label><br />
            <label><input type="Checkbox" name="Genre" Value="Jazz" /> Jazz</label><br />
              </td>
        <td width="396" rowspan="2">
        	
            <label><input type="Checkbox" name="Genre" Value="Jewish_Klezmer" /> Jewish/Klezmer</label><br />
        	<label><input type="Checkbox" name="Genre" Value="Latin" /> Latin</label><br />
            <label><input type="Checkbox" name="Genre" Value="Motown" /> Motown</label><br />
            <label><input type="Checkbox" name="Genre" Value="Oldies" /> Oldies</label><br />
            <label><input type="Checkbox" name="Genre" Value="Opera" /> Opera</label><br />
            <label><input type="Checkbox" name="Genre" Value="Popular-Top_40" /> Popular/Top 40</label><br />
            <label><input type="Checkbox" name="Genre" Value="R_B" /> R&amp;B</label><br />
            <label><input type="Checkbox" name="Genre" Value="Reggae" /> Reggae</label><br />
            <label><input type="Checkbox" name="Genre" Value="Religious" /> Religious</label><br />
            <label><input type="Checkbox" name="Genre" Value="Rock" /> Rock</label><br />
            <label><input type="Checkbox" name="Genre" Value="Scottish" /> Scottish</label><br />
            <label><input type="Checkbox" name="Genre" Value="Swing" /> Swing</label><br />
            <label><input type="Checkbox" name="Genre" Value="Oldies" /> Oldies</label><br />
            <label><input type="Checkbox" name="Genre" Value="Zydeco" /> Zydeco</label><br />
            <label><input type="Checkbox" name="Genre" Value="Other" /> Other</label><br />        </td>
        </tr>
    
    Code (markup):
    Here is the php
    $Genre = Trim(stripslashes($_POST['Genre'])); 
    
    
    $Body .= "Genre: ";
    $Body .= $Genre;
    $Body .= "\n";
    Code (markup):
     
    caligrafx, Aug 28, 2009 IP
  7. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #7
    You should use arrays for the HTML. Instead of:

    
    name="Genre"
    
    Code (markup):
    Change them all to:

    
    name="Genre[]"
    
    Code (markup):
    In your PHP, you will access the value as an array:

    
    foreach($_POST['name'] as $sub => $value)
    {
     // Do the work
    }
    
    PHP:
     
    ThePHPMaster, Aug 28, 2009 IP
  8. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #8
    I am not sure if I am putting this in the right place. Could you please tell me where to put the "foreach" at?

    Thanks,
    Adam

    <?php
    
    $EmailFrom = "xxxxxxxxxxxxxxxxxxxxxxx";
    $EmailTo = "xxxxxxxxxxxxxxxxxxxxxxx";
    $Subject = "xxxxxxxxxxxxxxxxxxxxxxx";
    $Event_Date = Trim(stripslashes($_POST['Event_Date'])); 
    $Event_Day = Trim(stripslashes($_POST['Event_Day'])); 
    $Event_Type = Trim(stripslashes($_POST['Event_Type'])); 
    $Event_Location = Trim(stripslashes($_POST['Event_Location'])); 
    $Event_Zip_Code = Trim(stripslashes($_POST['Event_Zip_Code'])); 
    $Total_Guests = Trim(stripslashes($_POST['Total_Guests'])); 
    $Indoor_Outdoor = Trim(stripslashes($_POST['Indoor_Outdoor'])); 
    $Start_Time = Trim(stripslashes($_POST['Start_Time'])); 
    $End_Time = Trim(stripslashes($_POST['End_Time'])); 
    $Genre = Trim(stripslashes($_POST['Genre[]'])); 
    $Budget = Trim(stripslashes($_POST['Budget'])); 
    $Quote_Reason = Trim(stripslashes($_POST['Quote_Reason'])); 
    $Full_Name = Trim(stripslashes($_POST['Full_Name'])); 
    $Phone_Number = Trim(stripslashes($_POST['Phone_Number'])); 
    $Zip_Code = Trim(stripslashes($_POST['Zip_Code'])); 
    $Email_Address = Trim(stripslashes($_POST['Email_Address'])); 
    
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    foreach($_POST['Genre'] as $sub => $value)
    {
     // Do the work
    }
    
    // are you human?
    if ($_POST['human'] == "fd964") {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contact_thanks.html\">";
    } else {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    // prepare email body text
    $Body = "";
    $Body .= "Event_Date: ";
    $Body .= $Event_Date;
    $Body .= "\n";
    $Body .= "Event_Day: ";
    $Body .= $Event_Day;
    $Body .= "\n";
    $Body .= "Event_Type: ";
    $Body .= $Event_Type;
    $Body .= "\n";
    $Body .= "Event_Location: ";
    $Body .= $Event_Location;
    $Body .= "\n";
    $Body .= "Event_Zip_Code: ";
    $Body .= $Event_Zip_Code;
    $Body .= "\n";
    $Body .= "Total_Guests: ";
    $Body .= $Total_Guests;
    $Body .= "\n";
    $Body .= "Indoor_Outdoor: ";
    $Body .= $Indoor_Outdoor;
    $Body .= "\n";
    $Body .= "Start_Time: ";
    $Body .= $Start_Time;
    $Body .= "\n";
    $Body .= "End_Time: ";
    $Body .= $End_Time;
    $Body .= "\n";
    $Body .= "Budget: ";
    $Body .= $Budget;
    $Body .= "\n";
    $Body .= "Quote_Reason: ";
    $Body .= $Quote_Reason;
    $Body .= "\n";
    $Body .= "Full_Name: ";
    $Body .= $Full_Name;
    $Body .= "\n";
    $Body .= "Phone_Number: ";
    $Body .= $Phone_Number;
    $Body .= "\n";
    $Body .= "Zip_Code: ";
    $Body .= $Zip_Code;
    $Body .= "\n";
    $Body .= "Email_Address: ";
    $Body .= $Email_Address;
    $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=quote_thanks.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>
    Code (markup):
     
    caligrafx, Aug 28, 2009 IP
  9. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #9
    I have try everything I could think of could someone please help me. Where do I put this at?

    Thanks,
    Adam
     
    caligrafx, Aug 31, 2009 IP