編集/更新:
phpコードをprocess.phpファイルからcontact.phpファイルの先頭に移動しましたが、機能しました。では、contact.phpページにリダイレクトされていないprocess.phpファイルには何が欠けていますか?
これはcontact.phpの私のhtmlです
<?php echo $message; ?>
<form action="process.php" method="post" name="sign_up">
<input type="text" name="first_name" placeholder="First Name" value="<?php echo $_POST[first_name]; ?>" required/>
<input type="text" name="last_name" placeholder="Last Name" value="<?php echo $_POST[last_name]; ?>" required/><br>
<label class="bill-address">Billing Address:<br>
<input type="text" name="address1" placeholder="Address 1" value="<?php echo $_POST[address1]; ?>" required/><br>
<input type="text" name="address2" placeholder="Address 2" value="<?php echo $_POST[address2]; ?>" /><br>
<input type="text" name="city" placeholder="City" value="<?php echo $_POST[city]; ?>" required/>
</label>
<?php
$state_list = array('AL'=>"Alabama",
'AK'=>"Alaska",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'WV'=>"West Virginia",
'WI'=>"Wisconsin",
'WY'=>"Wyoming");
?>
<select name="state">
<?php
while(list($k,$v) = each($state_list)) {
$selected = '';
if ($k == $_POST[state]) {
$selected = ' selected="true"';
}
echo "<option value=\"$k\"$selected>$v</option>\n";
}
?>
</select>
<input type="text" name="zip" placeholder="Zip Code" value="<?php echo $_POST[zip]; ?>" required/>
<br style="clear: left;" />
<input type="email" name="email" placeholder="you@youremail.com" value="<?php echo $_POST[email]; ?>" required/>
<input type="tel" name="phone" placeholder="Phone" value="<?php echo $_POST[phone]; ?>" required/>
<h3>Choose your Package</h3>
<select name="package">
<option value="Free">Free!</option>
<option value="Basic">Basic</option>
<option value="Corporate">Corporate</option>
<option value="Enterprise">Enterprise</option>
<option value="Enterprise_20">Enterprise 20</option>
<option value="Enterprise_50">Enterprise 50</option>
<option value="Enterprise_100">Enterprise 100</option>
</select>
<h3>Add Media Package?</h3>
<input type="radio" name="Yes" value="yes" />Yes
<input type="radio" name="No" value="no" />No
<button type="submit" class="btn">Send »</button>
<?php echo $success_message; ?>
</form>
そしてこれは私のprocess.phpです
//validate email
function is_valid_email($email) {
$result = true;
$pattern = '/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i';
if(!preg_match($pattern, $email)) {
$result = false;
}
return $result;
}
//when submit has been pressed, begin form validate
if(isset($_POST['submit'])) {
$valid = true;
$message = '';
if ( $_POST['first_name'] == "" ) {
$message .= "Please include your first name. ";
$valid = false;
}
if ( $_POST['last_name'] == "" ) {
$message .= "Please include your last name. ";
$valid = false;
}
if ( $_POST['address1'] == "" ) {
$message .= "Please include your billing address. ";
$valid = false;
}
if ( $_POST['city'] == "" ) {
$message .= "Please enter a city. ";
$valid = false;
}
if ( $_POST['state'] == "" ) {
$message .= "Please select a state. ";
$valid = false;
}
if ( $_POST['zip'] == "" ) {
$message .= "Please include a zip code. ";
$valid = false;
}
if ( $_POST['phone'] == "" ) {
$message .= "Please include your phone number. ";
$valid = false;
}
if ( !is_valid_email($_POST['email']) ) {
$message .= "A valid email is required. ";
$valid = false;
}
if ( $_POST['package'] == "" ) {
$message .= "You forgot to select a service package. ";
$valid = false;
}
if ( $valid == true ) {
$success_message = 'Brilliant I say! We will be in contact with you shortly.';
//clear form when submission is successful
unset($_POST);
}
}
動作していません。また、html5検証も機能していません。フォームのマークアップに何か問題がありますか?