Check radio box (while loop problem)
I have a PHP query that displays a response from my database in a while loop. What I have done is list several checkboxes that then gives additional data when selected and POSTed. The problem I am having is resolving a way to keep the checkbox in the checked state once it has been selected. As this is done in a loop I can't specify which name 'should' be checked.
I'm probably not making an ounce of sense. See the images below.
Thanks in advance!
I can't understand (I'm a poor italian who knows just a little bit of English...) if you need to reload the form after it has been posted or what.
When do you want the check has to been checked?
After you submit the form end you reload it or during the form construction with the database data?
That's important to me to help you.
I'll explain the process and maybe you'll understand clearer.
The first step is to type in a room name. This data is posted back to the page which PHP then deals with.. (?location=..., for example 109)
Then a user will tick a radiobox and press Submit again. I didn't want the ID of the radiobox to appear in the URL because then people will start to mess around and could force the wrong data. Thus, I have POSTed this data to the same page (again).
PHP checks that ?location is set, and that $_POST[radio] is also also. Now (corresponding) data will show.
The problem I have is because I am not moving away from the original page, PHP posts the data and that loses which radiobox is checked. The radiobox goes from a checked state to an unchecked state because PHP has just essentially refreshed the page.
Ok just a few things:
First Next time please post some code here in the forum, don't use images! This 'cause it's easier to make a copy and paste of it and to explain you where's the problem.
Second in the image you posted there is an error and I didn't see it.
You are forgetting the "action" attribute.
echo "<form method='post'>
You should write like this:
You have to do this also if you want to post it at the same page.
echo "<form method='post' action='/path/to/your_page.php'>
The receiver page has to contain the code to analyze sent by post.
You'll pick up the value with $_POST['name_of_radio']
I post you an example of this concentrated in the same page:
You can see its working here
<form action="./test.php?key=1" method="post">
<input type="radio" name="test" value="1"/>The value of radio is 1<br>
<input type="radio" name="test" value="2"/>The value of radio is 2<br>
<input type="radio" name="test" value="3"/>The value of radio is 3<br>
<input type="submit" name="Select" value="Post your choice"/></form>
echo "Now I got the value of radio, it is $toprint";
I hope that's enough to help you.
Sorry we're actually talking about two different things. The post data works OK and I can see further information regarding the printer ID selected (with a checkbox), however what I would like to do is keep the checkbox checked value. I'll create a quick image to explain..
Is that a little clearer?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)