Never mind on the last post I found why it was and stopped it. I am stuck again on another code. I want to copy the same format for my registration page, this is the code I tried to make by copying the contact form and adding fields.
Registration form
<!---Start Registration form---->
<form name="registationform" method="POST" action="confirmation.php">
<table width="550px">
</tr>
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">10 Digit Phone Number *<br />e.g. 1235550123 </label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="course">Course you would like to take *</label>
</td>
<td valign="top">
<select name="course">
<option></option>
<option value=" Beginner Pistol course on <?php echo $nextbeginner ?>"> Beginner Pistol - <?php echo $nextbeginner ?></option>
<option value="Beginner Pistol course on <?php echo $nextbeginner2 ?>"> Beginner Pistol - <?php echo $nextbeginner2 ?></option>
<option value="Concealed Carry course on <?php echo $nextconcealed ?>"> Concealed Carry - <?php echo $nextconcealed ?></option>
<option value=" Concealed Carry course on <?php echo $nextconcealed2 ?>"> Concealed Carry - <?php echo $nextconcealed2 ?></option>
<option value="Advanced Pistol course on <?php echo $nextadvanced ?>"> Advanced Pistol - <?php echo $nextadvanced ?></option>
<option value="Advanced Pistol course on <?php echo $nextadvanced2 ?>"> Advanced Pistol - <?php echo $nextadvanced2 ?></option>
<option value="Rifle or Shotgun instruction on <?php echo $nextrifle ?>"> Rifle or Shotgun - <?php echo $nextrifle ?></option>
</select>
</td>
</tr>
<tr>
<td valign="top">
How did you hear about CCWS? **
</td>
<td valign="top">
<select name="found">
<option></option>
<option value="web">Web</option>
<option value="friend">Friend</option>
<option value="brochure">Brochure</option>
<option value="card">Card</option>
<option value="other">Other</option>
</select>
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments and how many people in your group *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="reset" value="Clear form"><input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
<!---End Registration form--->
<?php
/**
* Allows a developer to set a custom error message
* using a pre-built error structure
*
* @param string $error
* @return void
*/
function message_die($error) {
echo 'We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.<br /><br />';
echo $error . '<br /><br />Please go back and fix these errors.<br /><br /><a href="javascript:history.go(-1)">Go Back</a>';
exit;
}
/**
* Removes bad string values from a $_POST value to
* ensure email injection is avoided
*
* @param string $string
* @return string function
*/
function clean_string($string) {
$bad = array('content-type', 'bcc:', 'to:', 'cc:', 'href');
return str_replace($bad, '', $string);
}
// Regular expressions
$emailRegex = '/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/';
$lastNameRegex = '/^[M-z]+$/';
$firstNameRegex = '/^[A-z]+$/';
$courseRegex = '/^[A-z]+[-]([A-z0-9_]+)+$/';
$foundRegex = '/^[A-z]+$/';
$telephoneRegex = '/^[0-9]{10}/';
if (isset($_POST['email_form'])) {
// Required fields
$requiredFields = array(
'emailto' => array('length' => 1, 'regex' => false, 'error' => 'Please select a valid email address!'),
'first_name' => array('length' => 1, 'regex' => $firstNameRegex, 'error' => 'Please enter a valid first name!'),
'last_name' => array('length' => 1, 'regex' => $lastNameRegex, 'error' => 'Please enter a valid last name!'),
'course' => array('length' => 1, 'regex' => $coursRegex, 'error' => 'Please select a course and date!'),
'found' => array('length' => 1, 'regex' => $foundRegex, 'error' => 'Please let us know how you found us!'),
'email' => array('length' => 1, 'regex' => $emailRegex, 'error' => 'Please enter a valid email address!'),
'telephone' => array('length' => 1, 'regex' => $telephoneRegex, 'error' => 'Please enter a valid 10 digit telephone number!'),
'comments' => array('length' => 2, 'regex' => false, 'error' => 'Please enter a comment thats at least 2 characters long!')
);
foreach($requiredFields as $k => $v) {
if ((isset($_POST[$k]) && strlen($_POST[$k]) < $v['length'] && $v['regex'] == false) ||
(isset($_POST[$k]) && (strlen($_POST[$k]) < $v['length'] || ($v['regex'] != false && !preg_match($v['regex'], $_POST[$k]))))) {
message_die($v['error']);
} else {
// Clean up the string of any unwanted values
$_POST[$k] = clean_string(trim($_POST[$k]));
}
}
$sendto = "test@yahoo.com";
$email_subject = "CCWS";
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_from = $_POST['email'];
$telephone = $_POST['telephone'];
$course = $_POST['course'];
$found = $_POST['found'];
$comments = $_POST['comments'];
$email_message = "Form details below.\
\
";
$email_message .= "First Name: " . $first_name . "\
";
$email_message .= "Last Name: " . $last_name . "\
";
$email_message .= "Email: " . $email_from . "\
";
$email_message .= "Telephone: " . $telephone . "\
";
$email_message .= "Course: " . $course . "\
";
$email_message .= "Found us: " . $found . "\
";
$email_message .= "Comments: " . $comments . "\
";
$headers = "From: " . $email_from . "\\r\
";
$headers .= "Reply-To: " . $email_from . "\\r\
";
$headers .= "X-Mailer: PHP/" . phpversion() . "\\r\
";
//if (mail($sendto, $email_subject, $email_message, $headers)) {
echo "Thank's <strong><u>{$first_name}</u></strong>!<br />\
";
echo "We have successfully receieved your registration form and we will contact you as soon as possible.\
";
/*} else {
echo "An error has occurred while trying to send your contact form request, please try again!<br /><a href=\\"javascript:history.go(-1)\\">Go Back</a>\
";
}*/
} else {
message_die('Hack attempt!');
}
?>
I am getting the error Hack attempt!