First off Hello! I'm Akidi, I've never actually messed with php until recently when my little brother wanted a project, I figured what the hell, no deadline and it'll give me a chance to try and work on this new language, I'm very familiar with Javascript ( no it is not Java, totally separate languages ). Anyway I found this same page form validation ( here : http://snipplr.com/view/3498/php-form-validation-and-processing-same-page/ ) and attempted to modify it to more appropriately suit my needs, however, when I try to run it ( the file itself has 755 permissions so should execute ), it does not show anything, no form, nothing 😕. Any help would be greatly appreciated!
<?php
function VerifyForm(&$values, &$errors) {
$tmpday = preg_replace('/\D/gi','',$values['dayphone']);
$tmpeve = preg_replace('/\D/gi','',$values['eveningphone']);
if (strlen($values['firstname']) === 0) {
$errors['name'] = 'First name is to short';
}
if (strlen($values['lastname']) == 0) {
$errors['lastname'] = 'Last name must be filled in';
}
if (strlen($values['address']) == 0) {
$errors['address'] = 'Address must be filled in';
}
if (strlen($values['city']) == 0) {
$errors['city'] = 'City must be filled in';
}
if (strlen($values['state']) == 0) {
$errors['state'] = 'State must be filled in';
}
if (strlen($values['zip']) == 0) {
$errors['zip'] = 'Zip must be filled in';
}
if (strlen($values['dayphone']) == 0) {
$errors['dayphone'] = 'Day Phone must be filled in';
} else if (strlen($tmpday) != 10) {
$errors['dayphone'] = 'Day Phone must have 10 digits example: ###-###-#### or (###) ###-####';
}
if (strlen($values['eveningphone']) == 0) {
$errors['eveningphone'] = 'Evening Phone must be filled in';
} else if (strlen($tmpeve) != 10) {
$errors['eveningphone'] = 'Evening Phone must have 10 digits example: ###-###-#### or (###) ###-####';
}
if (strlen($values['email']) == 0) {
$errors['email'] = 'Email must be filled out';
}
if (strlen($values['confirmeamil']) == 0 $values['email'] != $values['confirmemail']) {
$errors['confirmemail'] = 'Email and confirm email must match';
}
if (strlen($values['checkin']) == 0) {
$errors['checkin'] = 'Checkin date must be filled out';
}
if (strlen($values['checkout']) == 0) {
$errors['checkout'] = 'Checkout must be filled out';
}
if (strlen($values['roomcount']) == 0) {
$errors['roomcount'] = 'Number of rooms requested is missing';
}
if (strlen($values['personperroom']) == 0) {
$errors['personperroom'] = 'Number of people per room must be filled out';
}
return (count($errors) == 0);
};
function DisplayForm($values, $errors) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rancho Reservation Form</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<div>
<h1>To make a reservation, please fill out the form below:</h1>
All items required
</div>
<div id="formErrors">
<?php
if (count($errors) > 0) {
$msg = "There were some errors in your sbmitted form, please correct them and try again.\n";
foreach ($errors as $val) {
msg .= $val . "<br />";
}
echo msg;
}
?>
</div>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" class="form">
<fieldset>
<legend>Personal Details</legend>
<div class="segment segmentmod">
<label for="title">Title:</label>
<div class="textInput textInputmod">
<select name="title" id="title" class="textbox textmod">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select>
</div>
</div>
<div class="segment segmentmod">
<label for="firstName">First Name:</label>
<div class="textInput textInputmod">
<input type="text" id="firstname" name="firstName" class="textbox textmod" />
</div>
</div>
<div class="segment segmentmod">
<label for="lastName">Last Name:</label>
<div class="textInput textInputmod">
<input type="text" id="lastname" name="lastName" class="textbox textmod" />
</div>
</div>
<div class="segment">
<label for="address">Street Address:</label>
<div class="textInput">
<input type="text" id="address" name="address" class="textbox" />
</div>
</div>
<div class="segment segmentmod">
<label for="city" >City:</label>
<div class="textInput textInputmod">
<input type="text" id="city" name="city" class="textbox textmod" />
</div>
</div>
<div class="segment segmentmod">
<label for="state">State:</label>
<div class="textInput textInputmod">
<input type="text" id="state" name="state" class="textbox textmod" />
</div>
</div>
<div class="segment segmentmod">
<label for="zip">Zip:</label>
<div class="textInput textInputmod">
<input type="text" id="zip" name="zip" class="textbox textmod" />
</div>
</div>
<div class="segment segmentmodphone">
<label for="dayPhone">Daytime Phone:</label>
<div class="textInput textInputmodphone">
<input type="text" id="dayphone" name="dayPhone" class="textbox textmodphone" />
</div>
</div>
<div class="segment segmentmodphone">
<label for="eveningPhone">Evening Phone:</label>
<div class="textInput textInputmodphone">
<input type="text" id="eveningphone" name="eveningPhone" class="textbox textmodphone" />
</div>
</div>
<div class="segment">
<label for="email">Email:</label>
<div class="textInput">
<input type="text" id="email" name="email" class="textbox" />
</div>
</div>
<div class="segment">
<label for="confirmemail">Confirm Email:</label>
<div class="textInput">
<input type="text" id="confirmemail" name="confirmemail" class="textbox" />
</div>
</div>
</fieldset>
<fieldset>
<legend>Reservation Details</legend>
<div class="segment">
<label for="checkin">Checkin Date:</label>
<div class="textInput">
<input type="text" id="checkin" name="checkin" class="textbox" value="mm/dd/yyyy" />
</div>
</div>
<div class="segment">
<label for="checkout">Checkout Date:</label>
<div class="textInput">
<input type="text" id="checkout" name="checkout" class="textbox" value="mm/dd/yyyy" />
</div>
</div>
<div class="segment">
<label for="roomcount">Number of Rooms:</label>
<div class="textInput">
<input type="text" id="roomcount" name="roomcount" class="textbox" />
</div>
</div>
<div class="segment">
<label for="personperroom">Persons Per Room:</label>
<div class="textInput">
<input type="text" id="personperroom" name="personperroom" class="textbox" />
</div>
</div>
</fieldset>
<div class="button_div">
<input type="submit" value="Submit" class="buttons" />
</div>
</form>
</div>
</body>
</html>
<?php
}
function ProcessForm($values) {
$tmpday = preg_replace('/\D/','',$values['dayphone']);
$tmpeve = preg_replace('/\D/','',$values['eveningphone']);
$emailTo = 'foo@bar.com';
$msg = 'Client Information.';
$msg .= '\nName : ' . $values['firstname'] . ' ' . $values['lastname'];
$msg .= '\nAddress : ' . $values['address'] . '\n' . $values['city'] . ', ' . $values['state'] . ' ' . $values['zip'];
$msg .= '\nDaytime Phone : ' . preg_replace("/([1-9][0-9]{2})([1-9][0-9]{2})([0-9]{4})/", "($1) $2-$3", $tmpday) . '\nEvening Phone : ' . preg_replace("/([1-9][0-9]{2})([1-9][0-9]{2})([0-9]{4})/", "($1) $2-$3", $tmpeve);
$msg .= '\nEmail : ' . $values['email'];
$msg .= '\nCheck-In : ' . $values['checkin'] . '\nCheck-Out : ' . $values['checkout'];
$msg .= '\nNumber of Rooms Requested : ' . $values['roomcount'];
$msg .= '\nPersons Per Room : ' . $values['personperroom'];
$msg .= '\n\nGenerated : ' . date(dMy H:i:s T);
mail($emailTo, 'Reservation', $msg, "From: \"{$values['firstname']}\" <{$values['email']}>");
echo "<html><head><title>Thank you!</title></head><body>Thank you!<br />Your reservation has been sent</body></html>";
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$formValues = $_POST;
$formErrors = array();
if (!VerifyForm($formValues, $formErrors)) {
DisplayForm($formValues, $formErrors);
} else {
ProcessForm($formValues);
}
} else {
DisplayForm(null, null);
}
?>