Page 1 of 1
Please help with checkboxes in a form !
Posted: Fri Dec 19, 2003 3:53 pm
by amarquis
Hi there !
I'm quite new to php coding so my question might be easy for you to answer... hope so !
I have buit a form on my website that has 3 pages and now I would like to make a "recapitulation" page before the whole form is emailed. I want my recap form to be displayed like the original one, leaving the choice for the user to unselect or change some fields at this step.
I have no problem with textboxes but how can I recall the checkboxes states ? I want to have the checkboxes displayed and checked or not depending on user's choice in the previous pages.
How could I do that ?
Thanks for your help !
Posted: Fri Dec 19, 2003 4:26 pm
by DuFF
Check out this tutorial for some help with checkboxes in forms:
http://codewalkers.com/tutorials/12/4.html
Posted: Sat Dec 20, 2003 6:08 am
by amarquis
thanks !
Posted: Sat Dec 20, 2003 4:59 pm
by amarquis
Mmh.. not sure that this is what I need but.. Can you help with that part of code ?
if (isset($PERIPH1)) {
?> <input type="checkbox" name="PERIPH1" value="<?=$PERIPH1?>" checked> Keyboard <? }
This doesn't work... and I don't know why... but I would like to display a checked checkbox that appears only if "PERIPH1" has been checked on the previous page... the PERIPH1 value is sent to this page from the previous page.
It takes the same name PERIPH1 so that the user can change it's state on the recap page.
Can you help ?
Thanks
Posted: Sat Dec 20, 2003 8:25 pm
by DuFF
You will need to either use:
Code: Select all
<?php
if (isset($_POST['PERIPH1']))
// OR
if (isset($_GET['PERIPH1']))
?>
Depending on the <form> line in your HTML. So if the form method="post" then use $_POST, or if it is method="get" then use the $_GET.
Posted: Sun Dec 21, 2003 5:28 am
by amarquis
Thank you very much !
Does that mean that if I declare a value in my recap page I can use it like that :
And that if the value has been posted using POST method I'll always need to use
Code: Select all
<?php
if (isset($_POST['PERIPH1']))
?>
??
Thanks for your help ! I'm learning php from day to day...

Posted: Sun Dec 21, 2003 9:42 am
by DuFF
Yep, anytime you use a form you will need to use either $_GET or $_POST.
Check out this link:
http://www.php.net/manual/en/language.v ... ternal.php
Posted: Sun Dec 21, 2003 9:43 am
by amarquis
Well I still have a problem with that...
As I said before, I have a 3 pages form. My checkbox name="PERIPH1" is on page 1 and my recap page stands as page 4.
If I use
Code: Select all
<?php
if (isset($_POST['PERIPH1'])) {
?><input type="checkbox" name="PERIPH1" checked> Screen<?
}
?>
This works since this code stands on page 2, directly after my page 1 checkbox. But btw page 1 and my recap page, I send my values using html hidden fields using value="<?PERIPH1?>" and then the code reacts as if I always had a value for PERIPH1 which shouldn't occur when my checkbox is not checked...
Any ideas ? maybe is there another way than hidden fields to pass values across pages ?
Thanks !