Jump to content
Zeeshan Asghar

How To Get Data One form field to Table.

Recommended Posts

I have a question form which have many question with select option of yes or no i need help.

for example Question no 1 have 3 options which have 3 select field of yes or no

<br><div class="form-group"> 1. <label for="q1"> Are you presently taking Tobacco/Alcohol/Drugs/Medicines in any form during the past 12 months? </label><br>
Insured: <select name="q1opt1" data-placeholder="" class="flat-select" id="q1" type="select">
<option value="Yes" checked>Yes</option>
<option value="No">No</option>
</select>
Spouse: <select name="q1opt2" data-placeholder="" class="flat-select" id="q1" type="select">
<option value="No" checked>No</option>
<option value="Yes" >Yes</option>
</select>
Children: <select name="q1opt3" data-placeholder="" class="flat-select" id="q1" type="select">
<option value="No" checked>No</option>
<option value="Yes">Yes</option>
</select>
</div><br>

i want if user select yes of any one option Question No automatically show on below table in QUESTION NUMBER Field

For example; Q1 or Q3

<table >
  <tr>
    <th style="width: 90px;text-align: center;">QUESTION NUMBER</th>
    <th style="width: 150px;text-align: center;">NAME</th>
    <th style="width: 150px;text-align: center;">ILLNESS OR INJURY</th>
    <th style="width: 150px;text-align: center;">DATES OF TREATMENT</th>
    <th style="width: 150px;text-align: center;">DATE OF RECOVERY</th>
    <th style="width: 150px;text-align: center;">NAME OF PHYSICIAN</th>
  </tr>
  <tr>
    <td><input type="text" name="questionno" style="width: 150px"></td>
    <td><input type="text" name="name" style="width: 150px">  </td>
    <td><input type="text" name="illnessofinjury" style="width: 150px">  </td>
    <td><input type="date" name="dateoftreatment" style="width: 150px;padding: 12px;height: 50px;">  </td>
    <td><input type="date" name="dateofrecovery" style="width: 150px;padding: 12px;height: 50px;">  </td>
    <td><input type="text" name="nameofphysician" style="width: 150px">  </td>
  </tr>

</table>

how can i do this with PHP?

check my complete form and help me

 

form.php

Share this post


Link to post
Share on other sites

First, IDs need to be unique, it's not correct to have the same ID on more than one element.  And option elements don't have a "checked" attribute, checkboxes do.  Option elements have a "selected" attribute.  

To make it easier, you can add a hyphen or something to each name, like "q1-opt1".  In PHP you can get each of the values in $_POST (if the only things in $_POST are the select values, then you can just loop through $_POST), you can use explode to split up the name into parts like "q1" and "opt1", check the value they selected, and then you can save which questions they picked yes for.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...