THE BORE

General => The Superdeep Borehole => Topic started by: GilloD on July 03, 2008, 10:07:52 AM

Title: I have a very, very NOOB PHP question.
Post by: GilloD on July 03, 2008, 10:07:52 AM
So I have a form for a contest:

Code: [Select]
<form action="http://asilenttreatment.org/flashtest/emailtest.php" method="post" requirelogin=0>
<br>
Name:  <br>
<input type="text" name="name">
<br>
Email: <br>
<input type="text" name="email">
<br>
Recipe Name: <br>
<input type="text" name="recipename">
<br>
Recipe: <br>
<input type="text" name="recipe">
<br>
I have read and agreed to the <a href="http://asilenttreatment.org/flashtest/tos.html" target="_blank">Terms and Conditions</a>:
<input type="checkbox" name="tos" value="tos1"><br>
<input type="submit">

That submits to a PHP file:

Code: [Select]
<?
//POST passes everything, synatx is $variablename=$_POST['variableinflash']

$s_lb="\n";
$s_name=$_POST['name'];
$s_email=$_POST['email'];
$s_recipename=$_POST['recipename'];
$s_recipe=$_POST['recipe'];
$s_cbox=$_POST['tos'];
echo $s_tos;

//echo $s_name;
//echo $s_email;
//echo $s_recipe;
//echo $s_recipename;

//Create a variable "bodytext" that is the userse-mail,\n,recipename,\n,recipe
$s_bodytext=$s_email.$s_lb.$s_name.$s_lb.$s_recipename.$s_lb.$s_recipe;
echo $s_bodytext; 
//Send mail
mail("myemail","SummerSandwichContest",$s_bodytext);
?>


Simple. But I want to check and make sure that the Checkbox is 'checked'. I know Checkboxes pass no value if they're unchecked, but how do I capture a value to check in the first place? This is like the first bit of programming I've done in like 7 years, so help a bro out, yo.
Title: Re: I have a very, very NOOB PHP question.
Post by: tiesto on July 03, 2008, 10:20:40 AM
Been a while since I've done any sort of PHP, but I used to do web dev. a few years ago... Would you do something like:

Code: [Select]
<?php if($s_tos == "on"){echo " CHECKED";}?>>

Also, it looks like in your code, you have $s_cbox and $s_tos variables... which look to be the same thing. Is that a typo?
Title: Re: I have a very, very NOOB PHP question.
Post by: GilloD on July 03, 2008, 10:23:32 AM
Been a while since I've done any sort of PHP, but I used to do web dev. a few years ago... Would you do something like:

Code: [Select]
<?php if($s_tos == "on"){echo " CHECKED";}?>>

Also, it looks like in your code, you have $s_cbox and $s_tos variables... which look to be the same thing. Is that a typo?

Haha, Yes. Typo city! That should work, I'll give it a run. I found a few solutions. The only problem here is that the checkbox is a sort of legal waiver, so I can't process the form unless it's checked.
Title: Re: I have a very, very NOOB PHP question.
Post by: GilloD on July 03, 2008, 10:27:23 AM
What I ended up doing was 2-fold:

I created a hidden object in the HTML form that will always pass a value of "0", unless the box is checked and visible, in which case it'll pass a value of "1".

Inside the PHP form I gave tos a default value of 0. When it goes to nab the value, it'll either not exist and remain at 0 or will exist and swap up to 1. This should work. I have about 2 weeks to work on this
Title: Re: I have a very, very NOOB PHP question.
Post by: GilloD on July 03, 2008, 12:20:49 PM
So now I'm confused- What values do a checkbox pass to POST? I know they only pass when checked, but what do they pass: 1/0 on/off checked/unchecked? What kind of variable do I need to setup to catch that value? So far everything I tried just kills the file.
Title: Re: I have a very, very NOOB PHP question.
Post by: GilloD on July 03, 2008, 12:35:21 PM
I can so dumb. I forgot it passes along the pre-defined 'value'. So I just set the default tos value to "No" and if the box is checked it passes "Yes".