0
嘗試一些使用php和html的東西,我有問題試圖讓我所有的表單數據轉貼。我已經想出瞭如何做文本框。仍然在選擇框,收音機和複選框的損失。我會在HTML頁面內重新發布還是讓我的包含模板代碼處理它?粘性表單數據問題php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/rocks.css">
<title>About Us-- Rocks</title>
</head>
<body>
<?php include("templates/banner_navigation.php"); ?>
<div id="links_group">
<?php include("templates/menu.php"); ?> <!-- 1st include for navigation, stored in templates -->
</div>
<div id="about_us_form">
<?php include("templates/about_us_valid.php"); ?>
<form action="<?php echo $PHP_SELF;?>" method="post">
<table>
<tr><td>First name:</td><td><input type="text" name="contact_name" title="Enter your first name here" value="<?php if (isset($_POST['contact_name'])) echo $_POST['contact_name']; ?>" /></td></tr>
<tr><td>Email Address:</td><td><input type="text" name="contact_email" title="Enter your email here" value="<?php if (isset($_POST['contact_email'])) echo $_POST['contact_email']; ?>" ></td></tr>
<tr><td>Phone Number:</td><td><input type="text" name="contact_phone_number" title="555-555-5555" value="<?php if (isset($_POST['contact_phone_number'])) echo $_POST['contact_phone_number']; ?>" /></td></tr>
<tr><td>I prefer to be contacted by:</td><td><input type="radio" name="preference" value="Email" checked/>Email<input type="radio" name="preference" value="Phone" />Phone</td></tr>
<tr><td>I am interested in:</td> <td><select name="select_rocks"><option value="gold">Gold</option>
<option value="silver">Silver</option>
<option value="thorium" selected="selected">Thorium</option>
<option value="titanium">Titanium</option>
</select></td></tr>
<tr><td> I would like to ask about:</td></tr>
<tr><td><textarea name="that_textarea" rows ="10" cols="25" title="Enter your questions here!">
</textarea></td></tr>
<tr><td>I am also interested in:</td><td>
<tr><td>Gemstones <input type="checkbox" name="checkbox1[]" value="gemstones" /></td><tr>
<tr><td>Ore processing <input type="checkbox" name="checkbox1[]" value="oreprocessing" /></td></tr>
<tr><td><input type="hidden" name="checkbox1[]" value="" /> </td><tr>
<tr><td><input type="submit" value="submit" name="submitform" /></td></tr>
</table><br/>
</form>
</div>
</body>
的包括模板:
<?php
function check_for_cat($namecheck=false,$emailcheck=false){
if ($namecheck) $name_field_error = "(((Name Invalid!)))";
if ($emailcheck) $email_field_error = "(((Email Invalid!)))";
//Start of form
if($namecheck) echo "<tr><td>$name_field_error</td></tr>";
if($emailcheck) echo "<tr><td>$email_field_error</td></tr>";
}
if (!isset($_POST['submitform'])) {
check_for_cat();
} else {
$namecheck = false;
$emailcheck = false;
$contact_name = isset($_POST['contact_name']) ? trim($_POST['contact_name']) : '';
$contact_email = isset($_POST['contact_email']) ? trim($_POST['contact_email']) : '';
if (strlen($contact_name)<3) $namecheck = true;
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) $emailcheck=true;
if ($namecheck || $emailcheck){
check_for_cat($namecheck,$emailcheck);
} else {
echo '(((OMG the form is submitted!)))';
}
}
?>
它大概很容易做到的,我只是一直在尋找的代碼過長,感謝您的幫助!如果可能的話放一些代碼,谷歌和雅虎還沒有找到我需要看的東西。