Page 2 of 2

Re: Testing checkbox settings

Posted: Sun Jul 17, 2011 1:17 pm
by Jonah Bron
Can you link to the actual URL so I can try it myself? You can PM it to me if you want.

Re: Testing checkbox settings

Posted: Fri Jul 22, 2011 12:29 pm
by Jonah Bron
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:

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>
and here is the start of filter.php:

Code: 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;
Giomach
Okay, try removing the two header()s at the beginning of filter.php. Looks like those are messing things up.

Re: Testing checkbox settings

Posted: Sat Jul 23, 2011 5:22 pm
by giomach
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

Code: Select all

isset ($HTTP_GET_VARS)
in filter.php (without the header lines). It is not set.

Thanks for your continuing help.

Re: Testing checkbox settings

Posted: Sat Jul 23, 2011 8:09 pm
by Jonah Bron
Copy filter.php to back up it's contents, and remove all text and code from it. Instead, place this:

Code: Select all

<?php
print_r($_GET);
?>
And go to it via the form on download2.php.

Re: Testing checkbox settings

Posted: Sun Jul 24, 2011 8:34 am
by giomach
...place this:
<?php
print_r($_GET);
?>
Array ( [formSubmit] => Anuas )

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>
and with filter.php as above (three lines), the result is still the same. There's nothing in $_GET but [formSubmit].

PPS. I see that my checkbox <input> tags lack the endtag /, but adding these has made no difference.

Re: Testing checkbox settings

Posted: Sun Jul 24, 2011 10:34 am
by Jonah Bron
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

Posted: Sun Jul 24, 2011 1:59 pm
by giomach
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]

Re: Testing checkbox settings

Posted: Sun Jul 24, 2011 2:19 pm
by Jonah Bron
  1. If you don't check the checkboxes, they won't be sent at all. Did you make sure you checked them?
  2. 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

Posted: Tue Jul 26, 2011 5:11 am
by giomach
If you don't check the checkboxes, they won't be sent at all. Did you make sure you checked them?
.. or tested they weren't set!
If you want to pass a known parameter in a form, add it as a hidden input, like so:
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.)

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.