Testing checkbox settings
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Testing checkbox settings
Can you link to the actual URL so I can try it myself? You can PM it to me if you want.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Testing checkbox settings
Okay, try removing the two header()s at the beginning of filter.php. Looks like those are messing things up.giomach wrote:Sorry I didn't see your message until now.
The url is: --removed--
Remember the problem: trying to send control to filter.php when the submit button (labelled "Anuas") is pressed, but filter.php takes three parameters, of which only the first is known in advance. The other two should take their values from the checkboxes.
Thanks yet again,
Giomach.
In case it helps:
Here is the whole of download2.php:
and here is the start of filter.php:Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> </head> <body> <table> <tr> <td width="475"></td> <td width="175"></td> <td width="100"></td> </tr> <tr><form method="get" action="http://www.smo.uhi.ac.uk/~oduibhin/phptest/filter.php?fng_file=Lu054_utf8.txt"> <td>Text in column one</td> <td><input type="checkbox" value="2" name="fng_ceart"> box one<br /> <input type="checkbox" value="2" name="fng_marc"> box two<br /> </td> <td align="center"><input type="submit" name="formSubmit" value="Anuas" /></td> </form></tr> </table> </body> </html>
GiomachCode: Select all
<?php header ("Content-type: text/plain; charset=utf-8"); header ('Content-disposition: filename='.$_GET ['fng_file']); $marcailte = $_GET ['fng_marc']; // $marcailte = 3; // echo "###".$marcailte."###"\n; $ceartaithe = $_GET['fng_ceart']; // $ceartaithe = 2; // echo "$$$".$ceartaithe."$$$"\n; $infile = "http://www.smo.uhi.ac.uk/~oduibhin/phptest/".$_GET ['fng_file']; // echo $infile."#".$marcailte."#".$ceartaithe; // $infile = "input.txt"; // echo "£££".$infile."£££"\n; $lines = file ($infile); if ($marcailte == 2) $ceartaithe = 1; // echo $ceartaithe.'#'.$marcailte;
Re: Testing checkbox settings
I'm afraid that removing the two header lines didn't make any difference (to the problem), I still just get the directory listing.
With or without them, it seems that all three parameters are being picked up by the $_GETs in filter.php as the empty string, not just the two parameters supposed to come from the checkboxes, but even the parameter I give explicitly on the "action". I have no idea what would change this.
I just tested in filter.php (without the header lines). It is not set.
Thanks for your continuing help.
With or without them, it seems that all three parameters are being picked up by the $_GETs in filter.php as the empty string, not just the two parameters supposed to come from the checkboxes, but even the parameter I give explicitly on the "action". I have no idea what would change this.
I just tested
Code: Select all
isset ($HTTP_GET_VARS)Thanks for your continuing help.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Testing checkbox settings
Copy filter.php to back up it's contents, and remove all text and code from it. Instead, place this:
And go to it via the form on download2.php.
Code: Select all
<?php
print_r($_GET);
?>Re: Testing checkbox settings
Array ( [formSubmit] => Anuas )...place this:
<?php
print_r($_GET);
?>
Do you think there may be something wrong with the installation of php that I'm using?
[EDIT]
PS. I've now reduced download.php to just this:
Code: Select all
<html>
<body>
<form method="get" action="http://.../filter.php?fng_file=Lu054_utf8.txt">
<input type="checkbox" value="2" name="fng_ceart"> box one<br />
<input type="checkbox" value="2" name="fng_marc"> box two<br />
<input type="submit" name="formSubmit" value="Anuas" />
</form>
</body>
</html>PPS. I see that my checkbox <input> tags lack the endtag /, but adding these has made no difference.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Testing checkbox settings
Ah, the fact that the code I gave you indicates that there is something wrong with the code in filter.php. Can you post the current unabridged version of it?
Re: Testing checkbox settings
OK, I'll send the full source of filter.php by PM.
But I don't understand your reasoning. The misbehaviour of filter.php is completely explained by the fact that $_GET is being delivered to it containing nothing but [formSubmit]. The mystery is, why is this happening — why doesn't $_GET contain the two checkbox settings and the parameter supplied directly to filter.php in the form's "action" in download.php. Surely this can't be due to anything in filter.php itself? In particular, the fact that $_GET is not being delivered correctly to the 3-line version of filter.php can't be due to anything in the full version of filter.php, surely?
We've now reduced download.php to the extent that this is practically a textbook example! But it doesn't work like the textbooks say. Two things seem constant in my experiments:
1. the checkbox settings do not appear in either $_GET or $_POST, whether I set method to "get" or "post" (textbooks say the settings should appear in $_POST with method "post")
2. the parameter to filter.php supplied directly in "action" does appear in $_GET when method is set to "post", but setting method to "get" overwrites it with [formSubmit]
But I don't understand your reasoning. The misbehaviour of filter.php is completely explained by the fact that $_GET is being delivered to it containing nothing but [formSubmit]. The mystery is, why is this happening — why doesn't $_GET contain the two checkbox settings and the parameter supplied directly to filter.php in the form's "action" in download.php. Surely this can't be due to anything in filter.php itself? In particular, the fact that $_GET is not being delivered correctly to the 3-line version of filter.php can't be due to anything in the full version of filter.php, surely?
We've now reduced download.php to the extent that this is practically a textbook example! But it doesn't work like the textbooks say. Two things seem constant in my experiments:
1. the checkbox settings do not appear in either $_GET or $_POST, whether I set method to "get" or "post" (textbooks say the settings should appear in $_POST with method "post")
2. the parameter to filter.php supplied directly in "action" does appear in $_GET when method is set to "post", but setting method to "get" overwrites it with [formSubmit]
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Testing checkbox settings
- If you don't check the checkboxes, they won't be sent at all. Did you make sure you checked them?
- If you want to pass a known parameter in a form, add it as a hidden input, like so:
Code: Select all
<input type="hidden" name="fng_file" value="Lu054_utf8.txt" />
Re: Testing checkbox settings
.. or tested they weren't set!If you don't check the checkboxes, they won't be sent at all. Did you make sure you checked them?
Two vital pieces of information, which proved to be what I needed. They weren't particularly well explained in the textbooks I used. (And not explained at all was the fact, which I gathered earlier in the discussion, that defining an INPUT field sets $_GET ['name'] (at least when action="get"), that this is accessible in any PHP script, and that the same field name can be used in different forms without confusion.)If you want to pass a known parameter in a form, add it as a hidden input, like so:
All seems fine for the moment, and once again copious thanks to Jonah Bron for his patience and expertise. I think this thread can be closed now.
Giomach.