Jump to content

[SOLVED] POST data from checkbox


denoteone

Recommended Posts

I have a form that ask the user to check all that apply (among other questions). On submit the next page shows all the users answers. Giving them a chance to go back if they want to change one.  I am having problems with the checkboxes here is my code from both pages.

 

check all that apply
<INPUT TYPE=hidden NAME="relationship" Value="0"><br/>
<INPUT TYPE=CHECKBOX NAME="relationship" value="IT">Information Technolody<br/>
<INPUT TYPE=CHECKBOX NAME="relationship" value="Purchasing">Purchasing<br/>
<INPUT TYPE=CHECKBOX NAME="relationship" value="Marketing">Marketing<br/>
<INPUT TYPE=CHECKBOX NAME="relationship" value="Human_Resources">Human Resources<br/>
<INPUT TYPE=CHECKBOX NAME="relationship" value="Executive_Management">Executive Management</p><br/>

 

 

this is what is on the confirm page so the user can see what they checked and then submit.

  This is the list that you checked:  <?=$_POST['relationship']?><input type="hidden" value=" <?=$_POST['relationship']?>" name="relationship" />

Link to comment
https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/
Share on other sites

PHP does checkboxes and multi select boxes as array elements

 

<INPUT TYPE=hidden NAME="relationship[]" Value="0"><br/>
<INPUT TYPE=CHECKBOX NAME="relationship[]" value="IT">Information Technolody<br/>
<INPUT TYPE=CHECKBOX NAME="relationship[]" value="Purchasing">Purchasing<br/>
<INPUT TYPE=CHECKBOX NAME="relationship[]" value="Marketing">Marketing<br/>
<INPUT TYPE=CHECKBOX NAME="relationship[]" value="Human_Resources">Human Resources<br/>
<INPUT TYPE=CHECKBOX NAME="relationship[]" value="Executive_Management">Executive Management</p><br/>

 

Then

 

foreach ( $_POST['relationship']  AS $name = $value )
{
echo $value . "<br />";
}

it does work. I guess I am just not sure why. Could you provide a quicke xplination.  I understand that it saves the value in an array named relationships. and then loops and echos all the values....what is the

 AS $name => $value

  for?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.