Jump to content

Send Form Help


TorQueMoD
Go to solution Solved by TorQueMoD,

Recommended Posts

Hey all, not sure this is considered a "math" problem, but I don't have a clue what regex is so I figured this is the best bet. 

I've been successfully using this code that was originally generated for me back in march (can't for the life of me figure out where it was generated) but recentely I wanted to add a new field to my form. I seem to have successfully added the new field (phone number) but in doing so, its broken the gender value. 

 

Here's the actual form:

http://geekdomvancouver.com/register.html

 

and here's the PHP for the send.php file

 

 

<?php
 // CAPTCHA Code Start
require_once('recaptchalib.php');
  $privatekey = "6LcZZd4SAAAAAJ0QyQCCcfGpzOEjzZFybmIcvpB6";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
 
  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
  // CAPTCHA Code Finish
 
 // Submit Code Start 
 
  if(isset($_POST['email'])) {
     
    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "info@torquemod.com";
    $email_subject = "Geekdom Registration";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['city']) ||
        !isset($_POST['gender'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
     
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
$phone = $_POST['phone']; // required
    $city = $_POST['city']; // required
$gender = $_POST['gender']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
   $string_exp = "/^[0-9]{3}[0-9]{3}[0-9]{4}$/i";
  if(!preg_match($string_exp,$phone)) {
    $error_message .= 'The Phone Number you entered does not appear to be valid. Please enter only 10 numbers without - or spaces. Example: 7787787780 <br />';
  }
  if(strlen($city) < 2) {
    $error_message .= 'The City you entered do not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$gender)) {
    $error_message .= 'Please specify your gender<br />'; 
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
    $email_message .= "City: ".clean_string($city)."\n";
    $email_message .= "Gender: ".clean_string($gender)."\n";   
     
 
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
<!-- include your own success html here -->
 
<!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>
<title>Geekdom Vancouver - All encompassing geek exposition</title>
<META NAME="description" content="Geekdom Vancouver - All encompassing geek exposition held in Vancouver, British Columbia, Canada">
<META NAME="KEYWORDS" CONTENT="Geekdom, Vancouver, Expo, Fan Expo, Gaming Expo, Comic Con, Games, Cosplay, Geek, Nerd, Media, British Columbia, Canada, International">
<meta name="distribution" content="Global">
<META NAME="robots" content="index,follow">
<meta name="GOOGLEBOT" content="index,follow"> 
<META NAME="revisit-after" CONTENT="14 days">
</head>
<style type="text/css">
body,td,th {
font-family: "Comic Sans MS", cursive;
font-size: 18px;
color: #CCC;
}
body {
background-color: #333;
margin-left: 10px;
margin-top: 0px;
margin-right: 10px;
margin-bottom: 0px;
}
a:link {
color: #09F;
}
a:visited {
color: #B340FF;
}
h1 {
font-size: 36px;
color: #44B144;
}
</style>
<body>
<div align="center">
<!--Start Logo-->
<a href="http://www.geekdomvancouver.com/" target="_top"><img src="images/geekdom_logo_web.png" width="900" height="287" title="Geekdom Vancouver Home" alt="Geekdom Vancouver Home" /></a>        
<!--End Logo-->
</div>
<div align="left">
  <p>Thank you for registering for Geekdom Vancouver: Year Zero. If you were among the first 100 users to register, you will be sent an e-mail shortly confirming your registration details and information on how to obtain your free day pass. If you were not among the first 100 registrants, thank you very much for taking the time to register. We will contact you with ticket purchasing information as soon as it becomes available. Thank you again for supporting Geekdom Vancouver.</p>
</div>
</body>
</html>
 
<?php
}
}
?>
 

 

It doesn't matter what I do, the form always returns "We are very sorry, but there were error(s) found with the form you submitted. These errors appear below. Please specify your gender. Please go back and fix these errors."

 

I tried changing the gender from a drop down list to 2 radio buttons but that simply returns the same error without specifying what the actual problem is.

 

Anyone have any idea what I've done wrong? I'd rather not have to remove the gender field.

 

Thanks!

Link to comment
Share on other sites

$string_exp = "/^[0-9]{3}[0-9]{3}[0-9]{4}$/i";
  if(!preg_match($string_exp,$phone)) {

    $error_message .= 'The Phone Number you entered does not appear to be valid. Please enter only 10 numbers without - or spaces. Example: 7787787780 <br />';

  }

  if(strlen($city) < 2) {

    $error_message .= 'The City you entered do not appear to be valid.<br />';

  }

  if(!preg_match($string_exp,$gender)) {

    $error_message .= 'Please specify your gender<br />';

  }

Do you really expect gender to contain a 10-digit number?

Link to comment
Share on other sites

Ok, apologies if I wasn't clear before. I know virtually nothing about php. This send form was created using a generator that for some reason didn't want to take credit for its work cause I've been trying for days to find it again so I can just re-make the form but sadly I can't.

 

I have no idea what it means to put a condition after post mail nor how to do that and I also didn't realize that I was telling it to expect a 10 digit number after gender. Is there a way I can tell it to expect a drop down list for gender?

 

I'm guessing what happened is because I told it to expect a 10 digit number for the phone and then didn't re-specify what to expect for city and gender its looking for the same there? I'll have to figure out what the code is to tell it to expect a drop down list.

 

Thank you.

Edited by TorQueMoD
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.