Forum Moderators: coopster

Message Too Old, No Replies

Simple checkbox in Php form how?

Just need a checkbox...

         

silverbytes

3:21 pm on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My html form looks like this:

<input name="pet[]" value="dog" type="checkbox" checked>
<input name="pet[]" value="cat" type="checkbox" checked>

What to put in the php form file?

My other variables (non checkbox) looks like:

$receptor .= "name: $name\n";
$receptor .= "\n";

?

lorax

3:55 pm on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not sure I follow what you're trying to do. Are you trying to build a form from a PHP string variable?

silverbytes

4:02 pm on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to get some info from users from a form in an html page. The html form has this:

<form action="formokinscripcion.php" method="post" name="inscripcion" target="_blank" id="inscripcion" value="Inscribirme">

I have an html page with the form and a php page called formokinscripcion.php

the php page code looks like this:

<?
$formulario = "Bla";
$emailreceptor = "my@email.bla";
?>

<?
$receptor .= "E-mail: $email\n";
$receptor .= "\n";

$receptor .= "----------Remote info ----------\n";
$receptor .= "$HTTP_USER_AGENT\n";
$receptor .= "$REMOTE_ADDR\n";

mail("$emailreceptor", "$formulario", $receptor, "From: $email");
?>

But the html form has 4 checkboxes. And those values I'm not receiving. I don't know how the code for the php page should go...

lorax

4:30 pm on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ah.

First, your checkbox fields are creating an array called $pet. Which leads me to ask what do you want to do with the information from these fields once they are passed to the form handler (formokinscripcion.php)?

[added]Just looked your post over again - do you want to include the results of those fields in the email?[/added]

Willis

5:29 pm on Apr 26, 2004 (gmt 0)

10+ Year Member



Assumin all four checkboxes go under "pet[]" . . to me in "formokinscripcion.php" the php might go something like this:

$pet_boxs=$_REQUEST['pet']; //Collects Array
$pet_finished = ""; //He's the one we want
$pet_template = " \$pet_single,"; //Needed for later Eval
foreach($pet_boxs as $pet_single) //Breaks the Array down
{
eval("\$pet_finished.=\"".$pet_template."\";"); //Processes Array and ships information to $pet_finished
}

/*So Now, lets say the only boxes checked were "dog" and "cat" (in that order) . . if you were to print() $pet_finished , you would have litterly " dog, cat,".*/

So when shipping information to the email *thinks thats your intensions*, just ask for $pet_finished. Hope this is what you were lookin for.

silverbytes

6:49 pm on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just want to know if they like cats or dogs...
the same that all other info, just want an email telling:

What animal prefers?: cats, dogs

Or just cats, and so on...