<form name="addEvent" id="addEvent" action="appointment.php" onsubmit="" method="POST">
<fieldset>
<legend>Add Calendar Event:</legend><br>
<label>Name</label>
<input type="text" id="nitle" name="title" value="" maxlength="255"><span id="name1"></span><br><br>
<label>Date</label>
<select id="month" name="month">
<option value="0">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="day" name="day">
<option value="0">Date</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select id="year" name="year">
<option value="0">Year</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select><span id="year1"></span><span id="date1"></span><br><br>
<label>Start Time</label>
<input type="text" id="starttime" name="starttime" value="" placeholder="HH:MM" maxlength="7" >
<br>
<label>Contact E-mail</label>
<input type="text" id="email" name="email" placeholder="[email protected]" maxlength="80"><span id="email1"></span><br><br><br>
<input type="submit" id="submit" value="Add Event">
<input type="reset" id="reset" value="Reset Fields">
</fieldset>
</form>
PHP外部....不想把與HTML文件...PHP和HTML驗證
<?php
$name = $_POST['name'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$starttime = $_POST['starttime'];
$email = $_POST['email'];
if (strlen($name) < 3) {
echo '* Name must be at least 3 characters long' . '<br>';
}
if ($month == 0) {
echo '* Month must be chosen' . '<br>';
}
if ($day == 0) {
echo '* Day must be chosen' . '<br>';
}
if ($year != 2016) {
echo '* Year must be 2016' . '<br>';
}
if ($month == 2 && $day == 30) {
echo '* Feb 30th is an invalid date' . '<br>';
}
if ($month == 2 && $day == 31) {
echo '* Feb 31st is an invalid date' . '<br>';
}
if (empty($starttime)) {
echo '* Must input valid Appointment Time' . '<br>';
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo '* Must input valid email address' . '<br>';
}
else {
echo '<br>' . 'Submission Successful!' . '<br>';
}
?>
有沒有去任何人都可以進行測試,看看這是否正常工作,每次我測試一下它給了我無法POST /appointment.php(我不太擅長PHP,我想保持語法相同,因爲我可以更容易地閱讀它並理解它在做什麼)也是我正確連接它
我仍然得到不能POST/appointment.php但它爲你工作? – Michele
是的,它爲我工作。 –
@maybe其我......但是,謝謝 – Michele