Forum Moderators: coopster
I have checkboxes on the form.
How can I retain the checked checkboxes, when the form is submitted and the required field message is displayed.
In the form
<input type="checkbox" value="Planning" name="services[]"> Planning
<input type="checkbox" value="two" name="services[]"> two
<input type="checkbox" value="three" name="services[]"> three
php code to access the services and send mail
if(isset($_POST['services']))
{
foreach($_POST['services'] as $value)
{
$check_msg .= "Services: $value\n";
}
}
In the form I am doing required field validation for various fields. When the form is submitted the checked boxes are not retained.
How can I achieve this?
Thanks a lot.
Sai
If your trying to get the checkbox values AFTER the form is submitted this may help ya figure out what's going on.
[edit] No need for my code sample [/edit]
...But from the code you show I don't see anything intrinsically wrong. You may want to run a test without the form validation to discover if the problem lies there.
M. Cold
Thanks for your reply.
RonPK gave the code, I exactly wanted. You made it look so simple. Thanks.
One more question. I want to know, whether the way I am doing is right or there is a better way to do it.
Checkboxes
<input type="checkbox" value="Planning & Strategy" name="services[]"> Planning & Strategy
Getting the values to email
if(isset($_POST['services']))
{
foreach($_POST['services'] as $value)
{
$service_msg .= "$value<br/>";
}
}
I want to know whether it is neccesary to put the complete "Planning & Strategy" in the value field or their is a better way to do it.
Say I just put value="planning" and get "Planning & Strategy" while emailing in $service_msg.
Please guide.
Thanks.
Sai