Michele Michele - 2 years ago 71
PHP Question

Php and HTML validations

<form name="addEvent" id="addEvent" action="appointment.php" onsubmit="" method="POST">
<legend>Add Calendar Event:</legend><br>
<input type="text" id="nitle" name="title" value="" maxlength="255"><span id="name1"></span><br><br>

<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> &nbsp;
<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 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" >

<label>Contact E-mail</label>
<input type="text" id="email" name="email" placeholder="email@domain.com" maxlength="80"><span id="email1"></span><br><br><br>
<input type="submit" id="submit" value="Add Event">&nbsp; &nbsp;
<input type="reset" id="reset" value="Reset Fields">

php external.... don't want to put with html file...


$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>';


is there away anyone can test and see if this works everytime I test it out it gives me Cannot POST /appointment.php (I'm not too good at php and i would like to keep the syntax the same as i can read it easier and understand what it is doing) also am i connecting it properly

Answer Source

Your first mistake is your html control name is title and in php you are trying to get name so first please change that as shown in below.

$name = $_POST['name']; replace your this code with below code.

$name = $_POST['title']; after that you will get message as you set Submission Successful!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download