Hi,
I have a list of questions using checkboxes that are populated from a database.
As I will never always know which questions are going to be 'ticked', how can I determine which values are to be written to the database once the form has been submitted?
Thanks
dynamic checkbox values
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Hi,
Thanks for that post.
I have now implemented that segment of code and what I'm now trying to do is re-populate the checkboxes after a form submit so that the user doesn't have to select them again.
Here is the checkbox element:
This is the code used to retrieve the checked boxes on submit:
I have a feeling that the variable setting is dreadfully wrong...mainly because it doesn't work!!!
How would I retrieve the user selection of multiple checkboxes once they submit a form and then how would I store those selections in a php variables so that the checkboxes can be re-populated?
Thanks for that post.
I have now implemented that segment of code and what I'm now trying to do is re-populate the checkboxes after a form submit so that the user doesn't have to select them again.
Here is the checkbox element:
Code: Select all
<input type="checkbox" value="<? echo $intSessionId; ?>" name="chkSession[]" />Code: Select all
$_SESSION["dbChkSession"]=$_REQUEST["chkSession[]"];How would I retrieve the user selection of multiple checkboxes once they submit a form and then how would I store those selections in a php variables so that the checkboxes can be re-populated?
Code: Select all
$_SESSION["dbChkSession"]=$_REQUEST["chkSession"];- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
I thought that would suffice.
I also solved my next issue. That issue being: how to re-populate a form of checkboxes.
Here it is:
Assume database connection is called
This segment of code is placed inside a loop, so the "if" statement is used to match a value if one exists.
Works perfectly.
Thanks for your support.
I also solved my next issue. That issue being: how to re-populate a form of checkboxes.
Here it is:
Assume database connection is called
Code: Select all
<input style="width:15px; border:0;" type="checkbox" value="<? echo $intSessionId; ?>" name="chkSession[]"
<?
foreach($_SESSION['dbChkSession'] as $value)
{
if($value==$intSessionId)
{
echo "checked=\"checked\"";
}
}
?> />Works perfectly.
Thanks for your support.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
in_array() may be of interest.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London