I have a simple php form that is submitted and the details are emailed to someone. The problem is that there is a checkbox and if the checkbox is clicked then it sends the result as "Yes". However when it's not clicked I'd like the result to appear as "No" but I can't seem to do this. This is my code: - <?php $radiobutton = $_REQUEST['radiobutton'] ; $select = $_REQUEST['select'] ; $textarea = $_REQUEST['textarea'] ; $textfield = $_REQUEST['textfield'] ; $textfield2 = $_REQUEST['textfield2'] ; $textfield3 = $_REQUEST['textfield3'] ; $textfield4 = $_REQUEST['textfield4'] ; $checkbox = $_REQUEST['checkbox'] ;
-
// multiple recipients
-
$to = 'email@email.com' . ', '; // note the comma $to .= 'email@email.com'; // subject $subject = 'Feedback'; // if (empty($cip_req)) { // $cip_req = "No"; // } // message $message = "<b>Type Of Comment : </b>" . $radiobutton . "<br /><b>Comment Subject : </b>" . $select . "<br /><b>Comments : </b>" . $textarea . "<br /><b>Name : </b>" . $textfield . "<br /><b>Email : </b>" . $textfield2 . "<br /><br /><b>Phone : </b>" . $textfield3 . "<br /><b>Fax : </b>" . $textfield3 . "<br /><br /><b>Please contact me as soon as possible : </b>" . $checkbox; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Me <email@email.com>' . "\r\n"; $headers .= 'From: Website <email@email.com>' . "\r\n"; if (($checkbox)) { $checkbox = No; } // Mail it mail($to, $subject, $message, $headers); header("Location: index.php"); ?>
3 4473 Atli 5,058
Recognized Expert Expert
Hi Pope. Welcome to The Scripts!
If a checkbox is not checked, it will not be included in the HTTP request, which means that it will not exists in the $_POST, $_GET or $_REQUEST super-globals.
So to test if a checkbox has been checked, use the isset() function to see if it exists.
For example: -
<?php
-
if(isset($_POST['checked'])) {
-
echo "<p>The box IS checked!</p>";
-
}
-
else {
-
echo "<p>The box IS NOT checked!</p>";
-
}
-
?>
-
<form action="?" method="POST">
-
<input type="checkbox" name="checked" /><br />
-
<input type="submit" />
-
</form>
-
Hey, thank you very much! So for example, if I wanted, would it be possible to do something like this: -
<?php
-
if(!isset($_POST['checked'])) {
-
$checked = "No";
-
}
-
else {
-
}
-
?>
-
<form action="?" method="POST">
-
<input type="checkbox" name="checked" /><br />
-
<input type="submit" />
-
</form>
Atli 5,058
Recognized Expert Expert
Hey, thank you very much! So for example, if I wanted, would it be possible to do something like this: -
<?php
-
if(!isset($_POST['checked'])) {
-
$checked = "No";
-
}
-
else {
-
}
-
?>
-
<form action="?" method="POST">
-
<input type="checkbox" name="checked" /><br />
-
<input type="submit" />
-
</form>
Sure that would work, tho you should remove the empty else block, unless you plan to use it?
This code, by itself, would no do much, but it will compile and run fine.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Wayno |
last post by:
My php logs are coming up empty. I have done all I can think of, and
all that made sense to me. Can someone take a look at my php.ini
please and tell me what you think may be the problem.
I double-checked the path to my error log. It is in
/var/www/logs/php_error_log
Thanks. :)
-Wayne Stevenson
|
by: tornado |
last post by:
Hi all,
I am pretty new to PHP. I was reading PHP manual and trying out the
example from 2nd
chapter (A simple Tutorial). When i try to print the variable as
given in the example it returns
a empty value instead of returning the browser type.
Here is the line which i am using in my code and from manual:
<?php echo $_SERVER; ?>
|
by: Shufen |
last post by:
Hi,
I'm a newbie that just started to learn python, html and etc. I have
some questions to ask and hope that someone can help me on.
I'm trying to code a python script (with HTML) to get values from a
html form that consists of about 10 checkbox and a textbox where user
have to key in a value to perform a search.
From python tutors, I learned that I have to use the following method:
|
by: Bill |
last post by:
I have a catalog of books which need to be categorized into different
groups. Some of the books can be listed under more than one category.
I'm creating a page where I can assign a group of books to a category
by checking the checkbox next to their name (say I've looped out 100
of them, and check some, and not others) then submitting the form for
processing, so that those titles where the checkbox is checked will
get the categoryid number...
|
by: dx |
last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as
simple as setting oCheckBox.Checked = True.. yet for some reason it isn't.
I have a user control (ascx) that that has a checkbox and I can't get it to
default to checked. I tried radiobuttons and experienced the same result..
can't start them as checked. The really frustrating thing is that I set the
attributes of other input controls in the Init() with no problem.
...
| |
by: mamun |
last post by:
Hi All,
I have the following situation and am looking for answer in C#.
I have a datagrid and putting checkbox next to each record. In the
header I have a Delete button.
I want users to checkchekboxes and click the Delete button. That will
show a confirmation dialog message with the items they choose to
delete.
|
by: Sid |
last post by:
I hope someone could help me with this.
I am trying to setup a criteria to decide when to allow/not allow
user
to click on the check box. logically it looks simple but I am not
able
to incorporate in my data access page. I have a numerical field
called
tier status and right next to it I have a checkbox. I would like to
allow user to check and uncheck the checkbox as long as the tier
|
by: LionsDome |
last post by:
Hello,
I have a vb.net page which a bunch of checkboxes. A user can select a
checkbox(s) and hit the submit button to store those values in a SQL
Server table. This works fine with no problem the first time the user
submits. However when user submits a second time while changing some
of the selected boxes the page only re-submits the previosly selected
checkbox values. It's like its storing it somewhere in the cache or
something. My...
|
by: remya1000 |
last post by:
I have a field called Departments in my database. and I have 3 monitors. So when Page_Load, I need to check number of departments I have in database. And depends upon that number of departments I have, I need to calculate number of checkbox I need to display.
NumCheckBox = NumDepartments * 3
And then I need to create a table like structure with 4 fields. First column -Department Name and remaining 3 columns will be Monitor 1-3. and...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |