Jump to content

How To Get Data One form field to Table.

Zeeshan Asghar

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>
Spouse: <select name="q1opt2" data-placeholder="" class="flat-select" id="q1" type="select">
<option value="No" checked>No</option>
<option value="Yes" >Yes</option>
Children: <select name="q1opt3" data-placeholder="" class="flat-select" id="q1" type="select">
<option value="No" checked>No</option>
<option value="Yes">Yes</option>

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 >
    <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>
    <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>


how can i do this with PHP?

check my complete form and help me



Link to comment
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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...