0

Below is my html appointment form i created, it's a simple form that obtains a day, a time, and a name. I'd just like to know how to write this information to another file for later use, or also possibly send the information to an email address. I can't seem to figure it out. I'm still relatively new with web development and have tried many different methods to no avail. any help at all would be appreciated.

image of the form

<div class="col-md-5 col-md-offset-1">
  <div id="tab1">
    <div class="submit-form">
      <h4>
        Setup an appointment
      </h4>
      <form id="form-submit" action="" method="get">
        <div class="row">
          <div class="col-md-6">
            <fieldset>
              <label for="Date">Date:</label> <select required=""
              name='from' onchange='this.form.()'>
                <option value="">
                  Select a day...
                </option>
                <option value="Monday">
                  Monday
                </option>
                <option value="Tuesday">
                  Tuesday
                </option>
                <option value="Wednesday">
                  Wednesday
                </option>
                <option value="Thursday">
                  Thursday
                </option>
                <option value="Friday">
                  Friday
                </option>
              </select>
            </fieldset>
          </div>
          <div class="col-md-6">
            <fieldset>
              <label for="Time">Time:</label> <select required=""
              name='to' onchange='this.form.()'>
                <option value="">
                  Select a Time...
                </option>
                <option value="9:15 A.M">
                  9:15 AM
                </option>
                <option value="10:15 A.M">
                  10:15 AM
                </option>
                <option value="11:15 A.M">
                  11:15 AM
                </option>
                <option value="12:45 P.M">
                  12:45 PM
                </option>
                <option value="1:45 P.M">
                  1:15 PM
                </option>
                <option value="2:45 P.M">
                  2:15 PM
                </option>
                <option value="3:15 P.M">
                  3:15 PM
                </option>
                <option value="4:15 P.M">
                  4:15 PM
                </option>
              </select>
            </fieldset>
            <div class="nLabel">
              <fieldset>
                <label style="margin-left:-50px" for=
                "Name">Name:</label>
                <div class="nBox">
                  <fieldset>
                    <input style="margin-left:-110px" type=
                    "text" />
                    <div class="Btn">
                      <fieldset>
                        <button type="submit" style=
                        "margin-left:-69px" id="sBtn" class=
                        "button" value="click">OK</button>
                      </fieldset>
                    </div>
                  </fieldset>
                </div>
              </fieldset>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>

2
  • Are you trying to use php on the backend? The first step would be creating a php file in the same directory (like index.php), then sticking "index.php" in the 'action' part of the form tag. The action is where info gets posted. Commented Mar 21, 2018 at 2:01
  • there are many php form handling tutorials out there that should get you there rest of the way. i.e alvinalexander.com/php/php-simple-form-example-get-post-isset looks pretty clear Commented Mar 21, 2018 at 2:04

1 Answer 1

1

This should help you out. I have not done any validations on front-end or on the back-end. I would suggest you have a look at https://www.w3schools.com/php/php_form_validation.asp; https://www.w3schools.com/php/php_forms.asp

home.php:

<form action="appointment.php" method="POST">
    Name: <input name="name" type="text"><br/><br/>
    Select Day: <select name="day">
        <option value="Monday">Monday</option>
        <option value="Tuesday">Tuesday</option>
        <option value="Wednesday">Wednesday</option>
        <option value="Thursday">Thursday</option>
        <option value="Friday">Friday</option>
    </select><br/><br/>
    Select Time: <select name="appointment_time">
        <option value="9:15 A.M.">9:15 A.M.</option>
        <option value="10:15 A.M.">10:15 A.M.</option>
        <option value="11:15 A.M.">11:15 A.M.</option>
        <option value="12:45 P.M.">12:45 P.M.</option>
        <option value="1:45 P.M.">1:45 P.M.</option>
        <option value="2:45 P.M.">2:45 P.M.</option>
        <option value="3:15 P.M.">3:15 P.M.</option>
        <option value="4:15 P.M.">4:15 P.M.</option>
    </select><br/><br/>
    <input type="Submit" name="Submit">
</form>

appointment.php :

<?php
$name = $_POST["name"];
$day = $_POST["day"];
$appointment_time = $_POST["appointment_time"];
$txt = "\n".$name."\t".$day."\t".$appointment_time;
file_put_contents('appointments.txt', $txt.PHP_EOL , FILE_APPEND | LOCK_EX);
header("Location: home.php");
?>
Sign up to request clarification or add additional context in comments.

1 Comment

you guys are awesome, i greatly appreciate the help! I honestly couldn't appreciate it enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.