Jump to content

form script with code validation not working help!


randydg

Recommended Posts

signup.php

<?php
srand((double)microtime()*1000000);

// Run the random number seed through the MD5 function

$seed_string = md5(rand(0,9999));

// Chop the random string down to 5 characters

// This is the validation code we will use

$val_string = substr($seed_string, 17, 5);

?>
Signup</h1>
<form action="validateform.php" method="post">
  <table border="0" bgcolor="#ececec" cellspacing="5">
    <tr>
      <td width="353">First Name</td>
      <td width="197"><input type="text" size="10" name="fname"></td>
    </tr>
    <tr>
      <td>Last Name</td>
      <td><input type="text" size="10" name="lname"></td>
    </tr>
    <tr>
      <td>Phone Number</td>
      <td><input type="text" size="30" name="number"></td>
    </tr>
    <tr>
      <td>Street Address</td>
      <td><input type="text" size="30" name="address"></td>
    </tr>
    <tr>
      <td>City,State,zip</td>
      <td><input type="text" size="30" name="area"></td>
    </tr>
    <tr>
      <td>Username/Email address (3-16 char)</td>
      <td><input type="text" size="30" name="email"></td>
    </tr>
    <tr>
      <td>Password (3-16 char)</td>
      <td><input type="text" size="30" name="password"></td>
    </tr>
    <tr>
      <td>Email Filter* $1.50</td>
      <td><input type="text" size="5" name="filter"></td>
    </tr>
    <br>
    <tr>
      <td>*Email Filer protects you against spam & virus.</td>
    </tr>
    <tr>
      <td valign="top">Comments</td>
      <td><textarea name="comments" rows="6" cols="30"></textarea></td>
    </tr>
     <tr>
       <td>
         <div align="center">Type in the validation code number. (case sensitive)<br>                                  
          <!-- <img src="verify.jpg" height="40" width="200" alt="validation image" /><br> -->
          <?php  echo $val_string ?>
       </div></td>
       <td><input name="random" type="text" value=""> </td>
    </tr>
    <tr>
      <td></td>
      <td><input type="submit" value="Send">      </td>
    </tr>
  </table>
<input name="validation" type="hidden" value="<?php echo $val_string ?>"
</form>

 

validateform.php

 

<?php

if ($_POST['validation'] == trim($_POST['random'])){
?>
<?
$my_email = "[email protected]";
$continue = "www.somethinng.com/thankyou.php";
$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Check all fields for an email header.

function recursive_array_check_header($element_value)
{

global $set;

if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}

}

}

recursive_array_check_header($_REQUEST);

if($set){$errors[] = "You cannot send an email header";}

unset($set);

// Check referrer is from same site.

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."New customer.";

$message = stripslashes($message);

$subject = "**Service";

$headers = "From: " . $_REQUEST['email'];

?>
Your message has been sent </a>
<?
mail($my_email,$subject,$message,$headers);

} else {

echo "Please go back and get validated.";

}

?>

 

 

of course it would, you've echo'd out the successful response before you even run the mail() function.

 

now, your code is a mess, so there's not too much i'm going to do at this time, but changed some stuff at the bottom:

 

<?php
if ($_POST['validation'] == trim($_POST['random'])){
?>
<?
$my_email = "[email protected]";
$continue = "www.somethinng.com/thankyou.php";
$errors = array();

// Remove $_COOKIE elements from $_REQUEST.

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

// Check all fields for an email header.

function recursive_array_check_header($element_value)
{

global $set;

if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}

}

}

recursive_array_check_header($_REQUEST);

if($set){$errors[] = "You cannot send an email header";}

unset($set);

// Check referrer is from same site.

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."New customer.";

$message = stripslashes($message);

$subject = "**Service";

$headers = "From: " . $_REQUEST['email'];


if (mail($my_email,$subject,$message,$headers))
{
echo 'Your message has been sent.';
}
else
{
echo "Please go back and get validated.";
}
}//if ($_POST['validation'] == trim($_POST['random']))
?>

 

you gotta start indenting your code.  i can't read your code whatsoever.  look at this function:

 

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

 

it's one line.  why??  i, along with a lot of other people, don't have the time to re-structure code when trying to assist.  plus, you gotta be more informative with your issues.  it's not a guessing game.

I fixed this myself by adding this code to the validateform.php

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<title> signup</title>
<meta http-equiv="refresh" content="3;url=thankyou.php">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<br><h1>Your message has been sent</h1>
</center>
</div>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.