From: "Ron Piggott" on

I am trying to process a form where the user uses checkboxes:

<input type="checkbox" name="painDesc[]" value="1" />Sharp
<input type="checkbox" name="painDesc[]" value="2" />Stabbing
<input type="checkbox" name="painDesc[]" value="3" />Jabbing

When I do:

foreach($_REQUEST as $key => $val) {
$$key = $val;
echo $key . ": " . $val . "<br>";
}

The output is:

painDesc: Array

I need to know the values of the array (IE to know what the user is
checking), not that there is an array. I hope to save these values to the
database.

Thank you.

Ron

From: Ashley Sheridan on
On Tue, 2010-06-29 at 16:54 -0400, Ron Piggott wrote:

> I am trying to process a form where the user uses checkboxes:
>
> <input type="checkbox" name="painDesc[]" value="1" />Sharp
> <input type="checkbox" name="painDesc[]" value="2" />Stabbing
> <input type="checkbox" name="painDesc[]" value="3" />Jabbing
>
> When I do:
>
> foreach($_REQUEST as $key => $val) {
> $$key = $val;
> echo $key . ": " . $val . "<br>";
> }
>
> The output is:
>
> painDesc: Array
>
> I need to know the values of the array (IE to know what the user is
> checking), not that there is an array. I hope to save these values to the
> database.
>
> Thank you.
>
> Ron
>
>


You need to iterate that array, as that holds the values of everything
sent by the browser

Thanks,
Ash
http://www.ashleysheridan.co.uk


From: Shreyas Agasthya on
The painDesc array is what that should be iterated.

--Shreyas

On Wed, Jun 30, 2010 at 2:27 AM, Ashley Sheridan
<ash(a)ashleysheridan.co.uk>wrote:

> On Tue, 2010-06-29 at 16:54 -0400, Ron Piggott wrote:
>
> > I am trying to process a form where the user uses checkboxes:
> >
> > <input type="checkbox" name="painDesc[]" value="1" />Sharp
> > <input type="checkbox" name="painDesc[]" value="2" />Stabbing
> > <input type="checkbox" name="painDesc[]" value="3" />Jabbing
> >
> > When I do:
> >
> > foreach($_REQUEST as $key => $val) {
> > $$key = $val;
> > echo $key . ": " . $val . "<br>";
> > }
> >
> > The output is:
> >
> > painDesc: Array
> >
> > I need to know the values of the array (IE to know what the user is
> > checking), not that there is an array. I hope to save these values to
> the
> > database.
> >
> > Thank you.
> >
> > Ron
> >
> >
>
>
> You need to iterate that array, as that holds the values of everything
> sent by the browser
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>


--
Regards,
Shreyas Agasthya
From: "Ron Piggott" on
Am I on the right track? I don't know what to do with the second "FOREACH"

<?php

foreach($_REQUEST as $key => $val) {
$$key = $val;
echo $key . ": " . $val . "<br>";

if ( $val == "Array" ) {
$i=0;

foreach ($val) {
echo "$val[$i]<br>";
$i++;
}

}
}

?>

From: Jim Lucas on
Ron Piggott wrote:
> I am trying to process a form where the user uses checkboxes:
>
> <input type="checkbox" name="painDesc[]" value="1" />Sharp
> <input type="checkbox" name="painDesc[]" value="2" />Stabbing
> <input type="checkbox" name="painDesc[]" value="3" />Jabbing
>
> When I do:
>
> foreach($_REQUEST as $key => $val) {
> $$key = $val;
> echo $key . ": " . $val . "<br>";
> }
>
> The output is:
>
> painDesc: Array
>
> I need to know the values of the array (IE to know what the user is
> checking), not that there is an array. I hope to save these values to the
> database.
>
> Thank you.
>
> Ron
>
>

Think about it...

You would not <?php echo $_REQUEST; ?> and expect to get the value of any form
field would you. No, you wouldn't.

Given the following form...

<form>
Title<input type="text" name="title" value="" /><br />
Subject<input type="text" name="subject" value="" /><br />
<input type="submit" name="submit" value="Send it!" />
</form>

on the processing page, I would access those variables by writing the following.

echo $_REQUEST['title'];
echo $_REQUEST['subject'];

With that said, going back to your issue, you would do this:

if ( $_REQUEST['painDesc'] && count($_REQUEST['painDesc']) ) {
foreach($_REQUEST['painDesc'] as $key => $val) {
echo "{$key}:{$val}<br />";
}
}

--
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
 |  Next  |  Last
Pages: 1 2
Prev: file_get_contents limit
Next: form validation code