phpjqueryhtmlformsspry

Echo data in same form after submitting


I have a simple html form, which is included in a Spry Tabbed Panel. So, i would like to know, is it possible to submit that form, and only that form in the Panel, and then echo the submitted data back in the correct fields.

The echo part is not a problem doing it on a different page, or redirect after submitting, but my issue comes in with the other forms that should/can not be cleared if this one is submitted.

A hint in the right direction would be greatly appreciated!

Thank you in advance.

see code below:

(i know that the form action should not direct to a different file, but that is just how I've been using it until now...)

    <form action="caller_upd.php" method="post" name="contact" >
  <table width="200" border="0">
  <?php 
  $_SESSION['uid'] = $uid;
  ?>
    <tr>
    <td width="68">Title</td>
    <td width="4">:</td>
    <td width="144"><select name="title" id="title">
    <option selected="selected" disabled="disabled"</option>
      <option value="Mr">Mr</option>
      <option value="Ms">Ms</option>
      <option value="Dr">Dr</option>
    </select></td>
    <td width="6">&nbsp;</td>
    <td width="53">Number</td>
    <td width="3">:</td>
    <td width="301"><input style="color:rgb(255,0,0);" autofocus="autofocus"  type="text" name="contactnr" id="contactnr" /></td>
  </tr>
  <tr>
    <td>Name</td>
    <td>:</td>
    <td><input type="text" name="fname" id="fname" /></td>
    <td>&nbsp;</td>
    <td>Surname</td>
    <td>:</td>
    <td><input type="text" name="sname" id="sname" /></td>
  </tr>
  <tr>
    <td>Nature of Call</td>
    <td>:</td>
    <td><select name="type" id="type">
      <option disabled="disabled" selected="selected"></option>
      <option value="Domestic">Domestic</option>
      <option value="MVA">MVA</option>
      <option value="Assult">Assult</option>
      <option value="Padestrian">Padestrian</option>
      <option value="Transfer">Transfer</option>
      <option value="Private">Private</option>
</select></td>
    <td>&nbsp;</td>
    <td>Nr of Patients:</td>
    <td>:</td>
    <td><select name="nop" id="nop">
      <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>
    </select></td>
  </tr>
  <tr>
    <td>Location</td>
    <td><label for="location"></label></td>
    <td colspan="5"><input name="location" type="text" id="location" size="50" /> <?php if (!empty($location)){ ?><a href="street_map.php" target="_blank">Show Map</a><?php } else { } ; ?></td>
    </tr>
  <tr>
    <td>Comments:</td>
    <td colspan="6"><textarea name="comment" id="comment" cols="70" rows="5"></textarea></td>
    </tr>
  <tr>
    <td colspan="7" class="form"><input type="submit" name="submit"  id="submit" value="Update" /></td>
    </tr>
</table>
</form>

Solution

  • Check if the post value exists, and if so either select the option or put the value in the input element...

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" >
        <table width="200" border="0">
            <tr>
                <td width="68">Title</td>
                <td width="4">:</td>
                <td width="144"><select name="title" id="title">
                        <option value="Mr" <?php if(isset($_POST['title']) && $_POST['title'] == "Mr") echo "selected"; ?>>Mr</option>
                        <option value="Ms" <?php if(isset($_POST['title']) && $_POST['title'] == "Ms") echo "selected"; ?>>Ms</option>
                        <option value="Dr" <?php if(isset($_POST['title']) && $_POST['title'] == "Dr") echo "selected"; ?>>Dr</option>
                    </select></td>
                <td width="6">&nbsp;</td>
                <td width="53">Number</td>
                <td width="3">:</td>
                <td width="301"><input style="color:rgb(255,0,0);" autofocus="autofocus"  type="text" name="contactnr" id="contactnr" value="<?php if(isset($_POST['contactnr'])) echo $_POST['contactnr']; ?>" /></td>
            </tr>
            <tr>
                <td>Name</td>
                <td>:</td>
                <td><input type="text" name="fname" id="fname" value="<?php if(isset($_POST['fname'])) echo $_POST['fname']; ?>" /></td>
                <td>&nbsp;</td>
                <td>Surname</td>
                <td>:</td>
                <td><input type="text" name="sname" id="sname" value="<?php if(isset($_POST['sname'])) echo $_POST['sname']; ?>" /></td>
            </tr>
            ...
        </table>
    </form>