Question about passing multiple checkbox variables in form to display

Question about passing multiple checkbox variables in form to display

am 04.12.2007 22:45:42 von ATDave

So basically I'm just creating a form that I want the results e-mailed
to somebody. I have everything working except for the checkmark
sections that can have multiple answers. I'm a newbie when it comes
to PHP, so please be easy :)

So to show an example:

value="Self Confidence" />


value="Hair Make up" />


value="Poise Posture" />


value="Interview Skills" />



This is the checkbox options a user has. So on my confirmation page I
create the variable:

$SelfDevelopmentInterest = $_POST['SelfDevelopmentInterest'];

In the actual message, currently I print it out like this:

Self-Development Interest: $SelfDevelopmentInterest

When I get the e-mail, it only displays "Array". Say a user checks
the first three options, how can I pass all three and print it out in
the e-mail?

Re: Question about passing multiple checkbox variables in form to display in e-mail

am 04.12.2007 23:00:31 von Michael Fesser

..oO(ATDave)

>So basically I'm just creating a form that I want the results e-mailed
>to somebody. I have everything working except for the checkmark
>sections that can have multiple answers. I'm a newbie when it comes
>to PHP, so please be easy :)
>
>So to show an example:
>
> >value="Self Confidence" />
>

> >value="Hair Make up" />
>

> >value="Poise Posture" />
>

> >value="Interview Skills" />
>

>
>This is the checkbox options a user has. So on my confirmation page I
>create the variable:
>
>$SelfDevelopmentInterest = $_POST['SelfDevelopmentInterest'];
>
>In the actual message, currently I print it out like this:
>
>Self-Development Interest: $SelfDevelopmentInterest
>
>When I get the e-mail, it only displays "Array". Say a user checks
>the first three options, how can I pass all three and print it out in
>the e-mail?

For a really simple array print use either print_r() or var_dump(). For
a more sophisticated result you would have to loop through the array and
print out the values yourself in the way you like.

Micha

Re: Question about passing multiple checkbox variables in form to

am 04.12.2007 23:12:05 von ATDave

On Dec 4, 5:00 pm, Michael Fesser wrote:
> .oO(ATDave)
>
>
>
> >So basically I'm just creating a form that I want the results e-mailed
> >to somebody. I have everything working except for the checkmark
> >sections that can have multiple answers. I'm a newbie when it comes
> >to PHP, so please be easy :)
>
> >So to show an example:
>
> > > >value="Self Confidence" />
> >

> > > >value="Hair Make up" />
> >

> > > >value="Poise Posture" />
> >

> > > >value="Interview Skills" />
> >

>
> >This is the checkbox options a user has. So on my confirmation page I
> >create the variable:
>
> >$SelfDevelopmentInterest = $_POST['SelfDevelopmentInterest'];
>
> >In the actual message, currently I print it out like this:
>
> >Self-Development Interest: $SelfDevelopmentInterest
>
> >When I get the e-mail, it only displays "Array". Say a user checks
> >the first three options, how can I pass all three and print it out in
> >the e-mail?
>
> For a really simple array print use either print_r() or var_dump(). For
> a more sophisticated result you would have to loop through the array and
> print out the values yourself in the way you like.
>
> Micha

Thanks for the quick response. I don't know how to write the code for
an array, but I did try a couple things based on some
searching...unfortunately they did not work. I would assume I have to
do a loop through the array to print out the values...but should those
get assigned to more variables (one for each option) so that I can
actually pass them through in the e-mail?

Re: Question about passing multiple checkbox variables in form to display in e-mail

am 04.12.2007 23:28:24 von Michael Fesser

..oO(ATDave)

>On Dec 4, 5:00 pm, Michael Fesser wrote:
>>
>> For a really simple array print use either print_r() or var_dump(). For
>> a more sophisticated result you would have to loop through the array and
>> print out the values yourself in the way you like.
>
>Thanks for the quick response. I don't know how to write the code for
>an array, but I did try a couple things based on some
>searching...unfortunately they did not work.

It would help to post some code and say what did not work.

>I would assume I have to
>do a loop through the array to print out the values...but should those
>get assigned to more variables (one for each option) so that I can
>actually pass them through in the e-mail?

No variables needed, just a simple foreach loop and a little sanity
check. Something like:

if (isset($_POST['SelfDevelopmentInterest']) &&
is_array($_POST['SelfDevelopmentInterest'])) {
foreach ($_POST['SelfDevelopmentInterest'] as $value) {
// print out your stuff the way you like
print $value;
...
}
}

Micha

Re: Question about passing multiple checkbox variables in form to

am 05.12.2007 00:47:40 von ATDave

On Dec 4, 5:28 pm, Michael Fesser wrote:
> .oO(ATDave)
>
> >On Dec 4, 5:00 pm, Michael Fesser wrote:
>
> >> For a really simple array print use either print_r() or var_dump(). For
> >> a more sophisticated result you would have to loop through the array and
> >> print out the values yourself in the way you like.
>
> >Thanks for the quick response. I don't know how to write the code for
> >an array, but I did try a couple things based on some
> >searching...unfortunately they did not work.
>
> It would help to post some code and say what did not work.
>
> >I would assume I have to
> >do a loop through the array to print out the values...but should those
> >get assigned to more variables (one for each option) so that I can
> >actually pass them through in the e-mail?
>
> No variables needed, just a simple foreach loop and a little sanity
> check. Something like:
>
> if (isset($_POST['SelfDevelopmentInterest']) &&
> is_array($_POST['SelfDevelopmentInterest'])) {
> foreach ($_POST['SelfDevelopmentInterest'] as $value) {
> // print out your stuff the way you like
> print $value;
> ...
> }
>
> }
>
> Micha

I got it figured out without doing a loop.

$SelfDevelopmentInterest = implode(', ',
$_POST['SelfDevelopmentInterest']);

This worked perfectly!