RE: questions about if statements regarding a checkbox

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I placed an example of your code on my site.
I simply pasted exactly what you had, minus the actual mailing portion.

If you check the box you will see the array, if you do not check the box no array.

http://www.richardbuskirk.com/blunk.php


Forgive my prior post, I had not woke up yet.
So the wording is missing things though, yet not put to email mid sentence.

Code from site.


<?php
if(isset($_POST['reallife']))
{
print_r($_POST);
}
?>

<form action=? method=post>
<div align="center">
<table border="0"
   cellpadding="3" cellspacing="0" width="59%">
<tr>
<td colspan="2">
<h2 align="center">&nbsp;</h2>
<h2 align="center"><font color="blue" face="Arial">Contact Form</font></h2>
<p align="center">&nbsp;</p>
<td width="51%" align="right">
<p align="left"><font face="Arial">Email</font><font face="Times New
Roman">:</font><font face="Arial"> </font></td>
<td width="49%" align="left"><input type="text" name="email" size="20"></td>
</tr>

<tr>
<td width="51%" align="right">
<p align="left"><font face="Arial">First Name: </font></td>
<td width="49%" align="left"><input type="text" name="firstname"
size="20"></td>
</tr>
<tr>
<td width="51%" align="right">
<p align="left"><font face="Arial">Last Name: </font></td>
<td width="49%" align="left"><input type="text" name="lastname"
size="20"></td>
</tr>
<tr>
<td width="51%" align="right">
<p align="left"><font face="Arial">I know you in real life</font></td>
<td width="49%" align="left"><input type="checkbox" name="reallife"
size="20"></td>
</tr>
</table>
<p><input type="submit" value="contact me"
   name="B1"></p>

</center></div>
</form>
</td>
<td>&nbsp;</td>
</tr>
</table>






Richard L. Buskirk


-----Original Message-----
From: admin@xxxxxxxxxxxxxxxxxxx [mailto:admin@xxxxxxxxxxxxxxxxxxx] 
Sent: Sunday, October 31, 2010 10:37 AM
To: 'Ben Brentlinger'; php-general@xxxxxxxxxxxxx
Subject: RE:  questions about if statements regarding a checkbox

I tested your code and besides adding a form to the beginning it works.

If you want to see the results of the posted for try.

print_r($_POST);

you can see every position of the array passed and validate they are passing as intended.

Try this.

//if reallife is not set (Checked it will not pass)
// I am pretty sure I read where someone had responded with the isset


if(isset($_POST['reallife']))
{

print_r($_POST);

}



Richard L. Buskirk


-----Original Message-----
From: Ben Brentlinger [mailto:Ben@xxxxxxxxxxxx] 
Sent: Sunday, October 31, 2010 8:26 AM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  questions about if statements regarding a checkbox

Here's the code I'm using with the exception of the php tags and the 
redirect script that redirects to another page once the form is 
submitted.  This is just a test script I'm working on in order to teach 
myself php.  The php portion will be posted first, than the html form 
related to the php.  I've got the code inside tags similar to the "code" 
tag which only serves to serarate the php code from the html form.

[php_code]
$name = $_POST['firstname'] . ' ' . $_POST['lastname'];
$email = $_POST['email'];

if($_POST['reallife'] == "on")
{
$to = 'Ben@xxxxxxxxxxxx';
$subject ='test email one';
$msg = "$name has filled out the test form. \n" .
"this is just a test message";
mail ($to, $subject, $msg, 'From:' . $email);

} else {

$to = 'Ben@xxxxxxxxxxxx';
$subject ='test email two';
$msg = "$name has filled out the test form." ;
mail ($to, $subject, $msg, 'From:' . $email);
}

if($_POST['reallife'] == "on") {

$to = '$email';
$subject = "Thank you email number one";
$msg = "hello $name, \n" .
"thank you for filling out the form. \n" .
"This is the first of two test emails \n" .
"The second would have been sent \n" .
"if you had left the checkbox unchecked \n";
mail ($to, $subject, $msg, 'From:' . $Ben@xxxxxxxxxxxx);
}

header ("location:thankyoupage")
[/php_code]



[html_code]
<div align="center">
<table border="0"
   cellpadding="3" cellspacing="0" width="59%">
<tr>
<td colspan="2">
<h2 align="center">&nbsp;</h2>
<h2 align="center"><font color="blue" face="Arial">Contact Form</font></h2>
<p align="center">&nbsp;</p>
<td width="51%" align="right">
<p align="left"><font face="Arial">Email</font><font face="Times New 
Roman">:</font><font face="Arial"> </font></td>
<td width="49%" align="left"><input type="text" name="email" size="20"></td>
</tr>

<tr>
<td width="51%" align="right">
<p align="left"><font face="Arial">First Name: </font></td>
<td width="49%" align="left"><input type="text" name="firstname" 
size="20"></td>
</tr>
<tr>
<td width="51%" align="right">
<p align="left"><font face="Arial">Last Name: </font></td>
<td width="49%" align="left"><input type="text" name="lastname" 
size="20"></td>
</tr>
<tr>
<td width="51%" align="right">
<p align="left"><font face="Arial">I know you in real life</font></td>
<td width="49%" align="left"><input type="checkbox" name="reallife" 
size="20"></td>
</tr>
</table>
<p><input type="submit" value="contact me"
   name="B1"></p>

</center></div>
</form>
</td>
<td>&nbsp;</td>
</tr>
</table>
[/html_code]


This actual code that is on the portion of my hosting account which I 
use as my test server.  In my opinion, it's much cheaper to pay for a 
hosting account to use as a test server to teach myself php than it is 
to pay some collage professor to teach it to you only to be slapped in 
the face by having him assume you're learning php to be a freelance 
coder working for a company that does freelance work.  The truth is, I 
only have an interest in learning php to use in my own business and when 
I get good enough, I may do some freelancing on the side on sites like 
Scriptlance, but my main focus will be my own business and for anyone to 
have the audacity that I plan on working for someone else my whole life 
pisses me off, so that's why I'd much rather teach myself than to take a 
college class on php.

Thanks,

Ben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux