Thread: php lists and checkboxes
Results 1 to 3 of 3
Related
-
Form - checkboxes & file upload Forum: PHP Forum
Replies: 1 -
Checkboxes and arrays Forum: Javascript Forum
Replies: 18 -
Buttons and checkboxes Forum: Javascript Forum
Replies: 2 -
Checkboxes on form = mailto recipients Forum: CGI Perl Forum
Replies: 1
-
05-21-2007, 06:12 AM #1
php lists and checkboxes
Thanks for all your previous replies to last posting - appreciated. However, just one thing. What do you do with lists and checkboxes? Can you use them at the beginning with like the following: What do you put in to make sure it returns all the options and shows which ones are checked/chosen?
Code:$name=$_POST['name']; checkOK($name); $email=$_POST['email']; checkOK($email); $comments=$_POST['company']; checkOK($company);
HMCLast edited by vinyl-junkie; 05-24-2007 at 11:11 PM. Reason: Added code tags
-
05-23-2007, 04:34 PM #2
Re: I'm sorry to be a pain! But Help!
I'm not sure I understand what you're asking about with checkboxes? It looks like you're working with textboxes?
However if you want to see if a checkbox is checked you would use isset().
$checkbox = (isset($_POST['checkboxname']) ? "checked" : "not checked";
Also, what is in your checkOk() function?
-
05-24-2007, 02:25 PM #3
Re: I'm sorry to be a pain! But Help!
Hi flann,
thanks for reply. So far I have the below
but then after this (on the html form) there are several items to choose which can be either chosen by a 'list' option or by 'checkboxes' and I am not sure where this should be on the php code. If it helps the html. form is separate to the php code page.
Code:<?php function checkOK($field) { if (eregi("\r",$field) || eregi("\n",$field)){ die("Invalid Input!"); } } $name=$_POST['name']; checkOK($name); $email=$_POST['email']; checkOK($email); $comments=$_POST['company']; checkOK($company); $comments=$_POST['address']; checkOK($address); $comments=$_POST['telno']; checkOK($telno); $comments=$_POST['message']; checkOK($message); $to="EMAIL REMOVED - Send PM to This User Instead"; $message="$name just filled in your comments form. They said:\n$message\n\nTheir e-mail address was: $email"; if(mail($to,"Comments From Your Site",$message,"From: $email\n")) { echo "Thank you for your enquiry, we will contact you shortly."; } else { echo "There was a problem sending the mail. Please check that you filled in the form correctly."; } if ($_SERVER['REQUEST_METHOD'] != 'POST'){ $me = $_SERVER['PHP_SELF']; } else { error_reporting(0); if(isset($_POST['submit'])) { mail($to,$subject,$body,$headers); $to = ‘EMAIL REMOVED - Send PM to This User Instead'; $address = stripslashes($_POST['address']); $subject = "contact message"; $from = stripslashes($_POST['name']); $msg = "Message from: $from\n\n".stripslashes($_POST['message']); foreach($_POST ['check'] as $value){ $check_msg = "Checked: $value\n"; } $body = "From:$name_field\n Email:$email_field\n message:\n$check_msg";
i.e., would it be
Code:print_r ($_POST [checkbox']); Array ( [checkbox] = Array ( (0)= > checkboxname (1)= > checkboxname2 ) )
HMCLast edited by vinyl-junkie; 05-24-2007 at 11:13 PM. Reason: Added code tags
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum