How to process multiple forms with php -
i developing website have ten different pages ten different properties. each page have 2 forms 1 set appointment , 1 else. how process each form? right have processing page each form. total of twenty different processing pages. variables, names, , ids, add 2..3...4..etc. each form. correct way of doing it?
<form role="form" id="apptform2" name="apptform2" action="<?php echo htmlspecialchars($_server['php_self']); ?>" method="post"> <div class="form-group cushion"> <label for="apptname2">full name*</label> <input type="text" name="apptname2" class="form-control" id="apptname2" placeholder="last, first"> <?php if (isset($appterrors2['apptnamepgtwo1'])) { echo '<div class = "pink-text"/><p>', $appterrors2['apptnamepgtwo1'] , '</p></div>'; } ?> <?php if (isset($appterrors2['apptnamepgtwo2'])) { echo '<div class = "pink-text"/><p>', $appterrors2['apptnamepgtwo2'] , '</p></div>'; } ?> <?php if (isset($appterrors2['apptnamelengthpgtwo'])) { echo '<div class = "pink-text"/><p>', $appterrors2['apptnamelengthpgtwo'] , '</p></div>'; } ?> </div> <div class="form-group cushion"> <label for="apptemail2">email address*</label> <input type="email" name="apptemail2" class="form-control" id="apptemail2" placeholder="email"> <?php if (isset($appterrors2['apptemailpgtwo1'])) { echo '<div class = "pink-text"/><p>', $appterrors2['apptemailpgtwo1'] , '</p></div>'; } ?> <?php if (isset($appterrors2['apptemailpgtwo2'])) { echo '<div class = "pink-text"/><p>', $appterrors2['apptemailpgtwo2'] , '</p></div>'; } ?> </div> <div class="form-group cushion"> <label for="apptphone2">phone*</label> <input type="text" name="apptphone2" class="form-control" id="apptphone2" placeholder="phone"> <?php if (isset($appterrors2['apptphonepgtwo2'])) { echo '<div class = "pink-text"/><p>', $appterrors2['apptphonepgtwo2'] , '</p></div>'; } ?> </div> <div class="form-group cushion"> <label for="apptmessage2">message:</label> <textarea class="form-control" name="apptmessage2" rows="5" id="apptmessage2"></textarea> </div> <div class="cushion text-center"> <button type="submit" name="appt-form-2" class="btn btn-danger btn-md">request</button> </div> </form>
you need 2 forms, , within each form, add hidden , read-only input containing id of particular form, when form gets submitted, processing page know data. processing page have @ what's in "form_id" field know form submitted.
example:
<form action="processingpage.php"> <input type="text" name="form_id" value="appointmentform" readonly/> ... </form> <form action="processingpage.php"> <input type="text" name="form_id" value="somethingelseform" readonly/> ... </form>
technically, away hidden "form_id" input , use 2 different processing pages, example provided above if absolutely have use 1 processing page.