samedi 10 juin 2017

Store Multidimentional checkbox in database

I want to store checkbox in database.. but the checkbox is a bit complex than regular. Basically this is what I want to implement: http://ift.tt/2s94YQC

I am able to collect data from input and store it in an array, but I am not able to display it in sequence. example of inputs that I give: http://ift.tt/2t7ut1U Then this is what I get when I print_r() the array:

Array ( [aadhar] => Array ( [original] => 1 ) [pan] => Array ( [original] => 1 ) [address] => Array ( [xerox] => 1 ) [lightbill] => Array ( [original] => 1 ) )

My HTML code.

 <table>
      <tr>
      <td>Aadhar</td>
      <td><input type="checkbox" name="document[aadhar][original]" value="1"/></td>
      <td><input type="checkbox" name="document[aadhar][xerox]" value="1"/></td>
      </tr>
      <tr>
      <td>Pan Card</td>
      <td><input type="checkbox" name="document[pan][original]" value="1"/></td>
      <td><input type="checkbox" name="document[pan][xerox]" value="1"/></td>
      </tr>
      <tr>
      <td>Address</td>
      <td><input type="checkbox" name="document[address][original]" value="1"/></td>
      <td><input type="checkbox" name="document[address][xerox]" value="1"/></td>
      </tr>
      <tr>
      <td>Light Bill</td>
      <td><input type="checkbox" name="document[lightbill][original]" value="1"/></td>
      <td><input type="checkbox" name="document[lightbill][xerox]" value="1"/></td>
      </tr>
      <tr>
      <tr>
      <td><input type="submit" value="Submit" /></td>
      </tr>
    </table>

PROBLEM: After the user click submit, I want to show him, his selection,(like a confirmation). Example:

Document Selected
----------------- 
Adhaar - Original 
Pan card - Original
Address - xerox 
Light bill - Original

How should I do it? I tried foreach() but not working. Even when I try to simple display like echo document[adhaar][orginal]; still it shows error!




Aucun commentaire:

Enregistrer un commentaire