PHP - Multipel Checkboxes Not Working In Form
I keep getting the warning "unable to send"
and yet I use everything in the for correctly.
Please help me out. I have spent hours looking for an answer.
It also posts the checkboxes I select at the bottom. I just want to be sent to the email, not necessarily echoed so I can view it.
Thanks
<?php // Functions to filter user inputs function filterName($field){ // Sanitize user name $field = filter_var(trim($field), FILTER_SANITIZE_STRING); // Validate user name if(filter_var($field, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+/")))){ return $field; }else{ return FALSE; } } function filterEmail($field){ // Sanitize e-mail address $field = filter_var(trim($field), FILTER_SANITIZE_EMAIL); // Validate e-mail address if(filter_var($field, FILTER_VALIDATE_EMAIL)){ return $field; }else{ return FALSE; } } function filterString($field){ // Sanitize string $field = filter_var(trim($field), FILTER_SANITIZE_STRING); if(!empty($field)){ return $field; }else{ return FALSE; } } // Define variables and initialize with empty values $nameErr = $emailErr = $messageErr = ""; $name = $email = $subject = $message = ""; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ // Validate user name if(empty($_POST["name"])){ $nameErr = 'Please enter your name.'; }else{ $name = filterName($_POST["name"]); if($name == FALSE){ $nameErr = 'Please enter a valid name.'; } } // Validate email address if(empty($_POST["email"])){ $emailErr = 'Please enter your email address.'; }else{ $email = filterEmail($_POST["email"]); if($email == FALSE){ $emailErr = 'Please enter a valid email address.'; } } // Validate message subject if(empty($_POST["subject"])){ $subject = ""; }else{ $subject = filterString($_POST["subject"]); } // Validate user comment if(empty($_POST["message"])){ $messageErr = 'Please enter your comment.'; }else{ $message = filterString($_POST["message"]); if($message == FALSE){ $messageErr = 'Please enter a valid comment.'; } } // Check input errors before sending email if(empty($nameErr) && empty($emailErr) && empty($messageErr)){ // Recipient email address $to = 'youremail@example.com'; // Create email headers $headers = 'From: '. $email . "\r\n" . 'Reply-To: '. $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); // Sending email if(mail($to, $subject, $message, $Activity, $headers)){ echo '<p class="success">Your message has been sent successfully!</p>'; }else{ echo '<p class="error">Unable to send email. Please try again!</p>'; } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Contact Form</title> <style type="text/css"> .error{ color: red; } .success{ color: green; } </style> </head> <body> <h2>Contact Us</h2> <p>Please fill in this form and send us.</p> <form action="" method="post"> <p> <label for="inputName">Name:<sup>*</sup></label> <input type="text" name="name" id="inputName" value="<?php echo $name; ?>"> <span class="error"><?php echo $nameErr; ?></span> </p> <p> <label for="inputEmail">Email:<sup>*</sup></label> <input type="text" name="email" id="inputEmail" value="<?php echo $email; ?>"> <span class="error"><?php echo $emailErr; ?></span> </p> <p> <label for="inputSubject">Subject:</label> <input type="text" name="subject" id="inputSubject" value="<?php echo $subject; ?>"> </p> <p> <label for="inputComment">Message:<sup>*</sup></label> <textarea name="message" id="inputComment" rows="5" cols="30"><?php echo $message; ?></textarea> <span class="error"><?php echo $messageErr; ?></span> </p> <p> <input type="checkbox" name="Activity[Sit]" value="Sit" /> value1 <br> <input type="checkbox" name="Activity[sloth]" value="Sloth" /> value2<br> <input type="checkbox" name="Activity[Run]" value="Run" /> value3 <br> </p> <input type="submit" value="Send"> <input type="reset" value="Reset"> </form> <?php if(!empty($_POST['Activity'])) { foreach($_POST['Activity'] as $check) { echo $check; //echoes the value set in the HTML form for each checked checkbox. //so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5. //in your case, it would echo whatever $row['Report ID'] is equivalent to. } } ?> Edited by roguewonder, 14 August 2014 - 09:56 PM. Similar TutorialsExcuse my late night slop! But I read a thread earlier and I am working on a dynamic way to address checkboxes with some intuitive messages while processing, and I cannot get this to work right w/out errors.. Any ideas where I am going totally wrong with this? <form name="" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> One <input type="checkbox" name="checkbox[]" value="checkOneValue" /><br /> Two <input type="checkbox" name="checkbox[]" value="checkTwoValue" /><br /> Three <input type="checkbox" name="checkbox[]" value="checkThreeValue" /><br /> Four <input type="checkbox" name="checkbox[]" value="checkFourValue" /><br /> Five <input type="checkbox" name="checkbox[]" value="checkFiveValue" /><br /> <input type="submit" name="submit" value="Echo Checkbox Data!" /> </form> <?php if (isset($_POST['submit'])) { $checkbox = $_POST['checkbox']; foreach ($checkbox as $checkboxValue) if (empty($checkboxValue)) { echo "$checkboxValue is emtpy"; } else { echo "<br>$checkboxValue is checked"; } }; ?> When no checkboxes are selected, I am dealing with this S%#$! Otherwise it works as intended.. Notice: Undefined index: checkbox in C:\wamp\www\php_practice\0\checkbox_echoing_1.php on line 24 Warning: Invalid argument supplied for foreach() in C:\wamp\www\php_practice\0\checkbox_echoing_1.php on line 26 hello all, im wondering if it is possible to have multiple check boxes that get created based on the number of rows in a table (one representing each row) Code: [Select] <input type='checkbox' name='approve[$tid]' value='ON'> and then have a submit button at the bottom of the page that will find all of the checkboxes (it could be 1, or 100) and submit it to my form handling page. thanks So I've been scanning forms with checkboxes the same way for years and I can't help but think there's a better way. Sometimes when testing, it get caught in infinite loops the way I do it because basically I'll have it like so: formpage.php Code: [Select] <form action=processform.php> a1 <input type=hidden name=id value='1'> <input type=checkbox name=a1> <br> a2 <input type=hidden name=id value='2'> <input type=checkbox name=a2> // etc etc for all checkboxes and then, <input type=hidden name=tracker value='-1000'> <input type=submit value='Submit'> </form> processform.php Code: [Select] while(current($_POST) != '-1000') { // do stuff with current($_POST) to check the id and the value of the $_POST after it and then call next($_POST) to go to the next line } The reason I do this is because if a user clicks the a1 box, there is a value in the $_POST['a1'], but all boxes that are not checked do not pass through a variable. There must be a better way to do this Hey guys, So basically I created a page where people fill out some information such as their name, e-mail, phonenumer etc. This works perfectly by now. I also would like them to be able to check 6 checkboxes as optional fields something like: "I like to eat : (checkbox 1 ) cookies - (checkbox 2 ) chocolate .. etc" So when I give each html checkbox a name and id such as "cookies" how do I process this information in my php formscript? would it look like this? <?php session_start(); if(isset($_POST['Submit'])) { $youremail = 'myemail@gmail.com'; $fromsubject = 'subject email'; $chocolate = $_POST['chocolate']; $cookies = $_POST['cookies']; $to = $youremail; $mailsubject = ''.$fromsubject.' actionpage'; $body = $fromsubject.' Cookies: '.$cookies.' ?> The idea is that I will receive an e-mail that will tell me whether a box was checked or not and I am not sure how to make it work exactly. any help would be really awesome! William Hi
I'm totally green when it comes to php, but am learning it the hard way. Any help is appreciated.
I have a form the currenty uses a custom taxonomy but it has a text field, and I want it to call and list the taxonomy items with checkboxes so instead of entering words the visitor can just multiple check off the taxonomies that relate to them.
It's a job board, this is the job skill part that relates to their expertise.
There is a job category in the form, and I tried to use the syntax to get the taxonomy and implode it but
I really don't know what I'm doing.
See the "skills" item? I want to make that a bunch of checkboxes to allow selection the the pre defined resume_skills taxonomy.
http://outsourcing.j...it-resume-free/
Any help would be great, and I'm not sure what code I need to put in here.
Mark
I built a series of insertion forms to put entries into a mysql database. Everything is working fine, except that I just now realized my checkboxes don't put any entry in. It's just leaving it's respective smallint field as a default "0". Being new, I've must've overlooked how to handle these. The form's checkboxes have a bit of code in the value that remembers what users chose in case they have to backtrack and redo their form. How would I solve the problem and keep this code? Here's what all the checkboxes are written like: Code: [Select] <input type="checkbox" name="green_leaf" value="<?php if(isset($_POST['1'])) echo $_POST['1']; ?>" > green Hello! Everything on this form emails the way it should except for the checkboxes. The email simply states "Array" instead of what services are checked off. I don't understand PHP that well so I used a contact form and tried to modify it to include the checkboxes. Didn't work out Please help. <?php // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE! $yourEmail = "hello@mail"; // the email address you wish to receive these mails through $yourWebsite = ""; // the name of your website $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4 $requiredFields = "name,email,comments"; // names of the fields you'd like to be required as a minimum, separate each field with a comma // DO NOT EDIT BELOW HERE $error_msg = null; $result = null; $requiredFields = explode(",", $requiredFields); foreach($_POST["service"] as $value) { $service .= "$value\n"; } function clean($data) { $data = trim(stripslashes(strip_tags($data))); return $data; } function isBot() { $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz"); foreach ($bots as $bot) if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false) return true; if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ") return true; return false; } if ($_SERVER['REQUEST_METHOD'] == "POST") { if (isBot() !== false) $error_msg .= "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT']; // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score.. // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam $points = (int)0; $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "fuck", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur", "content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript"); foreach ($badwords as $word) if ( strpos(strtolower($_POST['comments']), $word) !== false || strpos(strtolower($_POST['name']), $word) !== false ) $points += 2; if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false) $points += 2; if (isset($_POST['nojs'])) $points += 1; if (preg_match("/(<.*>)/i", $_POST['comments'])) $points += 2; if (strlen($_POST['name']) < 3) $points += 1; if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500)) $points += 2; // end score assignments foreach($requiredFields as $field) { trim($_POST[$field]); if (!isset($_POST[$field]) || empty($_POST[$field])) $error_msg .= "Please fill in all the required fields and submit again.\r\n"; } if (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name']))) $error_msg .= "The name field must not contain special characters.\r\n"; if (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email']))) $error_msg .= "That is not a valid e-mail address.\r\n"; if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(\d+))?\/?/i', $_POST['url'])) $error_msg .= "Invalid website url.\r\n"; if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Automatic Form Email"; $message = "You received this e-mail message through your website: \n\n"; foreach ($_POST as $key => $val) { $message .= ucwords($key) . ": " . clean($val) . "\r\n"; } $message .= "\r\n"; $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n"; $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n"; $message .= 'Points: '.$points; if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) { $headers = "From: $yourEmail\n"; $headers .= "Reply-To: {$_POST['email']}"; } else { $headers = "From: $yourWebsite <$yourEmail>\n"; $headers .= "Reply-To: {$_POST['email']}"; } if (mail($yourEmail,$subject,$message,$headers)) { if (!empty($thanksPage)) { header("Location: $thanksPage"); exit; } else { $result = 'Thank You! Your email was successfully sent.'; $disable = true; } } else { $error_msg = 'Your mail could not be sent this time. ['.$points.']'; } } else { if (empty($error_msg)) $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']'; } } function get_data($var) { if (isset($_POST[$var])) echo htmlspecialchars($_POST[$var]); } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Contact Us</title> <meta charset="utf-8"> <link rel="stylesheet" href="css/reset.css" type="text/css" media="all"> <link rel="stylesheet" href="css/style.css" type="text/css" media="all"> <script type="text/javascript" src="js/jquery-1.4.2.min.js" ></script> <script type="text/javascript" src="js/cufon-yui.js"></script> <script type="text/javascript" src="js/Humanst521_BT_400.font.js"></script> <script type="text/javascript" src="js/Humanst521_Lt_BT_400.font.js"></script> <script type="text/javascript" src="js/cufon-replace.js"></script> <script type="text/javascript" src="js/roundabout.js"></script> <script type="text/javascript" src="js/roundabout_shapes.js"></script> <script type="text/javascript" src="js/gallery_init.js"></script> <!--[if lt IE 7]> <link rel="stylesheet" href="css/ie/ie6.css" type="text/css" media="all"> <![endif]--> <!--[if lt IE 9]> <script type="text/javascript" src="js/html5.js"></script> <script type="text/javascript" src="js/IE9.js"></script> <![endif]--> </head> <body> <!-- header --> <header> <div class="container"> <h1><a href="index.html"></a></h1> <nav> <ul> <li><a href="index.html">Home</a></li> <li><a href="aboutpg/about.html">About</a></li> <li><a href="currentpg/current.html">Current</a></li> <li><a href="contact.php" class="current">Contact</a></li> </ul> </nav> </div> </header> <!-- #gallery --> <section id="gallery"> <div class="container"> <ul id="myRoundabout"> <li><img src="images/postcard.jpg"></li> </ul> </div> </section> <!-- /#gallery --> <div class="main-box"> <div class="container"> <div class="inside"> <div class="wrapper"> <!-- aside --> <aside> <h2>Contact <span></span></h2> <!-- .contacts --> <ul class="contacts"> <li><strong>Owner:</strong></li> <li><strong>Business:</strong></li> <li><strong>Address:</strong></li> <li><strong> </strong></li> <li><strong>Phone:</strong></li> <li><strong>Email:</strong> <script type="text/javascript"> /*<![CDATA[*/ /*********************************************** * Encrypt Email script- Please keep notice intact * Tool URL: http://www.dynamicdrive.com/emailriddler/ * **********************************************/ <!-- Encrypted version of: [at] *****.*** //--> var emailriddlerarray=[83,80,87,105,110,99,55,55,64,121,97,104,111,111,46,99,111,109] var encryptedemail_id20='' //variable to contain encrypted email for (var i=0; i<emailriddlerarray.length; i++) encryptedemail_id20+=String.fromCharCode(emailriddlerarray) document.write('<a href="mailto:'+encryptedemail_id20+'"></a>') /*]]>*/ </script></li> </ul> <!-- /.contacts --> <h3>Miscellaneous info:</h3> <p><a href="http://www.fireislandferries.com" target="_blank">Fire Island Ferries</a></p> <p><a href="http://www.googlemaps.com" target="_blank">Google Maps</a></p> <p><a href="http://www.fireislandnews.net" target="_blank">Fire Island News</a></p> <p><a href="http://www.fireislandtide.net" target="_blank">Fire Island Tide</a></p> </aside> <!-- content --> <section id="content"> <article> <h2><span>*All fields are required.</span></h2> <?php if ($error_msg != NULL) { echo '<p class="error">ERROR: '. nl2br($error_msg) . "</p>"; } if ($result != NULL) { echo '<p class="success">'. $result . "</p>"; } ?> <form action="<?php echo basename(__FILE__); ?>" method="post"> <noscript> <p><input type="hidden" name="nojs" id="nojs" /></p> </noscript> <label>Services Required (check off as many as required):</label> <br> <input type="checkbox" name="service[ ]" id="service_0" value="addition" align="right">Addition<br> <input type="checkbox" name="service[ ]" id="service_1" value="remodeling">Remodeling<br> <input type="checkbox" name="service[ ]" id="service_2" value="roof">Roof<br> <input type="checkbox" name="service[ ]" id="service_3" value="foundation">Foundation<br> <input type="checkbox" name="service[ ]" id="service_4" value="kitchen">Kitchen<br> <input type="checkbox" name="service[ ]" id="service_5" value="bath">Bath(s)<br> <input type="checkbox" name="service[ ]" id="service_6" value="tile">Tile Work<br> <input type="checkbox" name="service[ ]" id="service_7" value="window">Windows<br> <input type="checkbox" name="service[ ]" id="service_8" value="deck">Deck<br> <input type="checkbox" name="service[ ]" id="service_9" value="painting">Painting<br> <input type="checkbox" name="service[ ]" id="service_10" value="power washing">Power Washing<br> <input type="checkbox" name="service[ ]" id="service_11" value="opening closing">Spring Opening/Fall Closing <br><br> <br /> <p> <small>Name: </small><input type="text" name="name" id="name" value="<?php get_data("name"); ?>" size="22" placeholder="First Last"/> <label for="name"></label> </p> <p> <small>Phone: </small><input type="text" name="email" id="email" value="<?php get_data("phone"); ?>" size="22" placeholder="(123) 123-4567"/> <label for="phone"></label> </p> <p> <small>Email: </small><input type="text" name="email" id="email" value="<?php get_data("email"); ?>" size="22" placeholder="you@email.com"/> <label for="email"></label> </p> <p> <small>Message: </small><textarea name="comments" id="comments" placeholder="Please write a brief message here."><?php get_data("comments"); ?></textarea> <label for="comments" style="display:none;"></label> </p> <p> <input name="submit" type="submit" id="submit" value="Submit Form" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> /> </p> </form> </div> </article> </section> </div> </div> </div> </div> <script type="text/javascript"> Cufon.now(); </script> </body> </html> Can someone please help? I am simply trying to email process a form with checkboxes and then redirect to a thank you page. It works fine as long as at least one checkbox is checked. It breaks if no checkboxes are checked using the implode function to list the "interests". I'm getting this error (and no redirect to my thank you page): Warning: implode() [function.implode]: Invalid arguments passed... <?php if (isset($_REQUEST['submit'])) { $email = $_REQUEST['email']; $firstName = $_REQUEST['firstName']; $lastName = $_REQUEST['lastName']; $address = $_REQUEST['address']; $city = $_REQUEST['city']; $state = $_REQUEST['state']; $zipcode = $_REQUEST['zipcode']; $homePhone = $_REQUEST['homePhone']; $cellPhone = $_REQUEST['cellPhone']; $interest = $_REQUEST['interest']; $imploded_interest = implode(',',$interest); $comments = $_REQUEST['comments']; $to = 'myemailhere@yahoo.com'; $subject = 'Volunteer Signup'; $message = " <html> <head> <title>Volunteer Signup</title> </head> <body> <p>Hello,<br/>A visitor has submitted the following information from the volunteer page:</p> <p><b>$firstName $lastName</b><br/> $address<br/> $city, $state $zipcode<br/><br/> Home Phone: $homePhone<br/> Cell Phone: $cellPhone<br/> Email: <strong>$email</strong><br/><br/> I would like to help in the following ways:<br/> $imploded_interest </p><br/> <p>$firstName would also like share the following comments:<br/> <q><i>$comments</i></q> </p> </body> </html> "; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: Volunteer Signup <myemailhere@yahoo.com>' . "\r\n"; mail($to, $subject, $message, $headers); } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Volunteer</title> </head> <body> <form id="VolunteerForm" method="post" action="thankyou.php"> <table> <tr> <td style="width:150px;">Email Address:</td> <td><input name="email" type="text" id="email" /></td> <td style="width:320px;" class="padtr"><strong>Ways I can help:</strong></td> </tr> <tr> <td>First Name:</td> <td><input name="firstName" type="text" id="firstName" /></td> <td class="padtr"><input name="interest[]" value="yard-sign" type="checkbox"/> Put a yard sign in my yard</td> </tr> <tr> <td>Last Name:</td> <td><input name="lastName" type="text" id="lastName" /></td> <td class="padtr"><input name="interest[]" value="fundraiser-at-home" type="checkbox" /> Host a fundraiser at my home</td> </tr> <tr> <td>Address:</td> <td><input name="address" type="text" id="address" /></td> <td class="padtr"><input name="interest[]" value="phone-calls" type="checkbox" /> Make phone calls to friends and family</td> </tr> <tr> <td>City:</td> <td><input name="city" type="text" id="city" /></td> <td class="padtr"><input name="interest[]" value="mailings" type="checkbox" /> Help with mailings</td> </tr> <tr> <td>State:</td> <td><input name="state" type="text" id="state" /></td> <td class="padtr"><input name="interest[]" value="doors-literature" type="checkbox" /> Help knock on doors and distribute literature</td> </tr> <tr> <td>Zip Code:</td> <td><input name="zipcode" type="text" id="zipcode" /></td> <td class="padtr"><input name="interest[]" value="donate" type="checkbox" /> Make a donation</td> </tr> <tr> <td>Home Phone:</td> <td><input name="homePhone" type="text" id="homephone" /></td> <td class="padtr"><input name="interest[]" value="endorsement" type="checkbox" /> Use my name as an endorsement</td> </tr> <tr> <td>Cell Phone:</td> <td><input name="cellPhone" type="text" id="cellphone" /></td> <td class="padtr"><input name="interest[]" value="newsletter" type="checkbox" /> Sign up for our newsletter</td> </tr> <tr> <td>Comments:</td> <td><textarea name="comments" id="comments" rows="5" cols="17"></textarea></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> <input type="submit" name="submit" id="submit" value="Submit Now" /> <input type="reset" name="reset" id="reset" value="Clear Form" /></td> </tr> </table> </form> </body> </html> Hello all,
I am completely sideways right now trying to get this to work. Basically I am attempting to make a form that fetches results based on a drop down and then populates a text box that the user can then edit. I have several issues, first of all, I would have to use check boxes for if a user has a certain file on record. Which would be editable, however, I have had issues displaying tinyint values of -1 as true and 0 as false.
Secondly, writing the data back to the table after clicking a submit button, I have still issues with checkboxes here and am thoroughly confused to if I need to use an array or what here.
Thirdly, should I be using PDO or mysql for this? We have an older NAS device that I will be running this on and the firmware is older.
All the info is stored in the same table, and would be selecting a single record at a time for a user to edit. I was thinking I would just write back ALL values to the table when submit is clicked? Is that a bad idea?
As you can tell I just need someone to kick my butt in the right direction, I feel like I have read all the different ways to skin a cat but confused myself in the process.
Thanks
guys, I have looked on google for this and apparently noone is doing it. I have 4 checkboxes and I want to send mail indicating which boxes were checked. the only code I've found is PHP that captures the *status* of the boxes, such as "on" or "off". I want to capture the names of the actual checkbox elements. Here is the code I'm currently testing (which just prints out "on" or "off" to indicate which boxes are checked): if(isset($_POST['checkboxes'])) { foreach($_POST['checkboxes'] as $selected){ echo $selected . "</br>"; } } else { echo "No Desired Contact Time Specified."; } if I check all 4 boxes for instance, I get this: on on on on any way to get the names? thanks! Hello All,
Being a newbie at PHP coding I'm at my wits end trying to figure out:
a) how to pull-in values from a delimeted text field (in a MySQL table) and check/select the appropriate checkboxes, based on the values that were stored in the text field,
b) how to write any changes (made by the user) back to the tables' text field.
Note that this is for an "update.php" file/process.
My "create.php" file/process uses the following HTML to display and accept the checkbox values:
<div class="control-group"> <label class="control-label">Limited Time Sale Days:</label> <div class="lts-checkboxes-container"> <label class="indent-to-the-left"> <input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='F'><span class='no-highlight'>Fri</span> </label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Sa'><span class='no-highlight'>Sat</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Su'><span class='no-highlight'>Sun</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='M'><span class='no-highlight'>Mon</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Tu'><span class='no-highlight'>Tue</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='W'><span class='no-highlight'>Wed</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Th'><span class='no-highlight'>Thu</span></label> </div> </div>And the code (certainly not the best code in the world, but it works) to collect, delemit/concatenate, and save to DB is as follows: if(empty($_POST['limited_time_sale'])) { // echo("You didn't select any weekday."); $selected_lts = ''; $limited_time_sale = ''; } else { $limited_time_sale = $_POST['limited_time_sale']; $N = count($limited_time_sale); $selected_lts = ''; // echo("You selected $N DoW(s): "); for($i=0; $i < $N; $i++) { // echo($limited_time_sale[$i] . " "); if ($i < ($N - 1)) { $selected_lts .= $limited_time_sale[$i] . "-"; } else { $selected_lts .= $limited_time_sale[$i]; } } } if(!empty($selected_lts)) { $limited_time_sale = $selected_lts; }Now, I've figured out how to bring-in, and separate the stored values using the following code, however I have no idea what to do next...in order to have only the approprite boxes checked/selected (in the event that all boxes were not selected during the create stage). $limited_time_sale = isset($values['limited_time_sale']) ? $values['limited_time_sale'] : ''; $checked_lts = explode("-", $limited_time_sale);In my "update.php" file, the HTML for the forms' checkboxes is as follows: <div class="control-group"> <label class="control-label">Limited Time Sale Days:</label> <div class="lts-checkboxes-container"> <label class="indent-to-the-left"> <input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='F' <?php echo $lts1; ?>><span class='no-highlight'>Fri</span> </label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Sa' <?php echo $lts2; ?>><span class='no-highlight'>Sat</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Su' <?php echo $lts3; ?>><span class='no-highlight'>Sun</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='M' <?php echo $lts4; ?>><span class='no-highlight'>Mon</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Tu' <?php echo $lts5; ?>><span class='no-highlight'>Tue</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='W' <?php echo $lts6; ?>><span class='no-highlight'>Wed</span></label> <label><input class='lts-checkbox' type='checkbox' name='limited_time_sale[]' value ='Th' <?php echo $lts7; ?>><span class='no-highlight'>Thu</span></label> </div> </div>Attached picture shows that selected checkboxes are saved to the text field as/in the format of "F-Sa-Su-M-Tu-W-Th" - if all checkboxes/weekdays were selected....or as "Sa-M-W-Th" - if only Sat, Mon, Wed, and Thu checkboxes were selected Thanks. Attached Files checkbox-Question.png 403.99KB 0 downloads Hi, my PHP code currently outputs the results from a users search by querying a backend postgresql database. As result/row is retuned to the user i would like to be able to detect whether or not they have checked a checkbox at the end of each rown in which case multiple rows can then be deleted from the database upon the user clicking a 'delete multiple records' button. I have no problem in being able to display the checkboxes on the webpage but i am a little unsure as to how to refernce them and detect which ones the user has checked. Given my database stores hostnames/IP addresses would it be best to name each checkbox to reflect the hostname or name the value it returns when checked to reflect the hostname. Given the above and that I also store the results of a users search in a $_SESSION['hosts'][][] array how can I then tie the two together? Thanks for reading. Hey there, Basically I'm having some difficulty getting this form to work: Code: [Select] <form action=getitem.php method=post name=form2><input type=hidden name=itemid value='1'> <input type=image src=items/ricketyoldsledge.png name=free class=img></form> It'll work if it's at the top of the code for the page I want it on, however I want it to be in a later position (I've included the PHP for the whole page below, so hopefully you can see what I mean). The error I get is that the form appears to send, only instead of sending me to getitem.php it just goes back to sledmakers.php. Code: [Select] <?php include('connect.php'); include('header.php'); include('loggedin.php'); echo 'blah blah"'; // Check profession $result = mysql_query("SELECT * FROM players WHERE id=".$_SESSION['id']) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $profession = $row['profession']; $level = $row['level'];} // if they're unemployed still if($profession == 'Unemployed'){ echo '<br><br><form action=sledmakers.php?talk=yes method=post name=form1> <input type=submit name=submit value="Talk to the man?"><bR><Br>'; } // if they're a Sledmaker elseif($profession == 'Sledmaker'){ echo 'Sledmaker';} // if they're not a Sledmaker else{ echo 'What? You\'re not a Sledmaker! Go away.';} $talk = $_GET['talk']; // if they're unemployed and pressed to speak with her if($talk == 'yes') { echo 'blahblah'; echo 'You look in the corner and find what you\'re looking for...<bR><br>'; ?> <form action=getitem.php method=post name=form2><input type=hidden name=itemid value='1'><input type=image src=items/ricketyoldsledge.png name=free class=img></form> <br><br><form action=sledmakers.php method=post name=form3> <input type=submit name=submit2 value="Become the Master Sledmakers's Apprentice?"><bR><Br> <?php } else{ echo '';} if(isset($_POST['submit2'])){ echo 'You are now an Apprentice Sledmaker!'; } include('footer.php'); ?> Can anybody help me out? :/ If you need more info, please just ask! I know this is very simple, but... Any way here is the code for my form, but it doesn't post to my database and there are no errors shown. Any ideas? thanks <? include("include/session.php");?> <? include('include/headder_login.php'); ?> <h1>Event Information : <? echo $session->username; ?></h1> <form> <form action="protimes.php" method="post" name="event information"> <input name="id" type="text" value=""> <input name="name" type="number" value="name" size="30"> <select name="event"> <option value="1">50 Front</option> <option value="2">50 Back</option> <option value="3">100 Front</option> </select> <input name="time" type="time" value"time" > <input name="date" type="date" value="date"> <input name="submit" type="button" value="submit" align="right"> <input type="reset" name="reset" value="reset"aligh="right"> </form> protimes.php file $sql="INSERT INTO `cbcrusta_test3`.`info` ( `id` , `name` , `event` , `time` , `date` ) VALUES ('$_POST[id]','$_POST[name]','$_POST[event]','$_POST[time]','$_POST[date')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; I am using this code to build a form: echo '<form method="post" action="mysql.php">'; echo '<table>'; echo '<tr><td>UserID:</td>'; echo '<td><input type="text" name="username"></td></tr>'; echo '<tr><td>Password:</td>'; echo '<td><input type="password" name="password"></td></tr>'; echo '<tr><td colspan="2" align="center">'; echo '<input type="submit" value="Log In"></td></tr>'; echo '</table></form>'; Alone, this form works, but when I add script above it to make it more functional, everything loads properly and I get no errors, but the form will not submit. The submit button is like a dead button. Anyone know why this could be happening? Hello! My name is DJ and I am new to PHP. Basically I designed a website with dreamweaver and on one of the pages I have a contact form. I used an internet tutorial to use php in order to finish the form. But now when someone submits their form, I don't receive an email and they just end up at a blank page. I don't understand why it's not working. Can you help me? Code: [Select] <?php /* Subject and Email Variables */ $emailSubject = 'Sales Inquiry'; $webMaster = 'sales@endorsebro.com'; /* Gathering Data Variables */ $name = $_POST['name']; $business_name = $_POST['business_name']; $phone_number = $_POST['phone_number']; $Email = $_POST['Email']; $website = $_POST['website']; $state = $_POST['state']; $budget = $_POST['budget']; $comments = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Business Name: $business_name <br> Phone Number: $phone_number <br> Email Address: $Email <br> Website: $website <br> State: $state <br> Budget: $budget <br> Comments: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as html */ $theResults = <<<EOD <html> <head> <title>Endorsebro</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #f1f1f1; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal; line-height: normal; font-weight: normal; color: #666666; text-decoration: none; } --> </style> </head> <div> <div align="left">Thank you for your interest! We will be in contact soon!</div> </div> </body> </html> EOD; echo "$theResults"; ?> Thank you for your time. Heres my code for the whole thing.. <?php if($_GET['view'] == 'vote') { $id="{$_GET['id']}"; if ($list_q = mysql_query("SELECT * FROM toplist WHERE id='$id'")) { if (mysql_num_rows($list_q)) { while($list_b=mysql_fetch_array($list_q)) { if ($list_b['ban'] == 0) { if ($list_b['staff'] == 0) { function capitalizeFirstCharacter($value) { $capitalize = preg_replace('/[a-z]/ie', 'strtoupper($0);', $value, 1); return $capitalize; } if(!empty($_POST['Submit'])) { if($_POST['spampre'] == "4iubg") { mysql_query("UPDATE toplist SET vote++ WHERE id = ". $_SESSION['id']) or die (mysql_error()); echo "<tr><td class='trow2'><span class='smalltext'> Thanks for voting. </span></td></tr>"; }else{ echo "<center>Spam Prevention is wrong.</center>"; } } $result = mysql_query("SELECT * FROM toplist WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_assoc($result); $id = $row["id"]; ?> <div class="navigation"> <!-- start: nav_bit --> <a href="http://runelegend.com/index.php">Runelegend</a> <!-- end: nav_bit --><!-- start: nav_sep_active --> / <!-- end: nav_sep_active --><!-- start: nav_bit_active --> <a href="http://runelegend.com/toplist">Server List</a> / <span class="active">Viewing <?php echo capitalizeFirstCharacter($list_b['servername']);?></span> <!-- end: nav_bit_active --> </div> <!-- end: nav --> <br /> <!-- end: header --> <form action="server.php?view=vote&id<?php ?>" method="post" id="registration_form"> <table border="0" cellspacing="0" cellpadding="5" class="tborder"> <script type="text/javascript" src="http://runelegend.com/jscripts/captcha.js?ver=1400"></script> <tr> <td><span class="smalltext">Please enter the text contained within the image on the right in to the text box below it. This process is used to prevent automated signups.</span></td> <td rowspan="2" align="center"><img src="http://runelegend.com/captcha.php?action=regimage&imagehash=35a910bc839af4d3c4e36faf471c600c" alt="Image Verification" title="Image Verification" id="captcha_img" /><br /><span style="color: red;" class="smalltext">(don't use caps)</span> </td> </tr> <tr> <td><input type="text" class="textbox" name="spampre" value="" id="spampre" style="width: 100%;" /><input type="hidden" name="imagehash" value="35a910bc839af4d3c4e36faf471c600c" id="imagehash" /></td> </tr> </table> <div align="center"> <input type="submit" class="button" name="Submit" value="Submit Registration!" /> </div> </form> <!-- end: member_profile_adminoptions --> </td> </tr> <?php } else { echo '<font color="red" align="center">There is no need to see this server, It isn\'t even a server, it is a staff member.</font><br/>'; } } else { echo '<font color="red" align="center">This server has been banned.<br>If you are the owner of this server, and wish to know why the server is banned from the list, login and go to the <a href="usercp">UserCP</a></font><br/>'; } }}}} ?> I am pretty much trying to make a Vote for system, but the only Problem Im having is the Form code. When I don't have a php code in the (action) part of the code it works, but If I do then it acts as if it's not even there. Edit: Fixed it. Hi, I am new to php, and I have run into a problem. The tutorial I am using has provided me with this exact code. But it does not work for me. Its very simple. Here is the HTML page: Code: [Select] <body> <FORM ACTION="welcome.php" METHOD=POST> First Name: <INPUT TYPE=TEXT NAME="name"> <INPUT TYPE=SUBMIT VALUE="GO"> </FORM> </body> And here is the php page: <body> <?php echo( "Welcome to our Web site, $name!" ); ?> </body> You can see the problem live at <http://www.freewaycreative.com/test> (dont mind the digits below) The name just does not show. Anyone know why? Thanks! Hi Guys, I am sure you will laugh at my coding attempt, but i need your help. I have set up a contact form and a PHP process to send the email. Everything appears to be working except the sending part. All fields validate as they should, the form forward to a thank you page as it should. But no emails are received either at my domain end or from the sender i am testing with. Here is my form code: Code: [Select] <form id="form1" name="form1" method="post" action="emailform.php" onsubmit="window.setTimeout(function(){window.location='/thankyou.html'},20); return true;"> <p><span id="sprytextfield1"> <label for="name">Name: </label> <input name="name" type="text" id="name" tabindex="10" /> <span class="textfieldRequiredMsg">Your name is required.</span><span class="textfieldMaxCharsMsg">No more than 50 characters in your Name.</span><span class="textfieldMinCharsMsg">Your Name must be atleast 4 characters long.</span></span></p> <p><span id="sprytextfield2"> <label for="email">Email: </label> <input type="text" name="email" id="email" tabindex="20" /> <span class="textfieldRequiredMsg">An Email Address is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span></p> <p><span id="spryselect1"> <label for="state">State</label> <select name="state" id="state" tabindex="30"> <option>ACT</option> <option>NSW</option> <option>Queensland</option> <option>Victoria</option> <option>Tas</option> <option>SA</option> <option>WA</option> <option>NT</option> </select> <span class="selectInvalidMsg">Please select a valid State.</span></span></p> <p>What styles are you interested in doing? <label for="styles"></label> <select name="styles" id="styles" tabindex="40"> <option>Portraits</option> <option>Fashion</option> <option>Swimwear</option> <option>Lingerie</option> <option>Art Nude</option> <option>All Styles Possible</option> <option>Just Curious for Now</option> </select> </p> <p>Please leave any Message or Comments Below:</p> <p><span id="sprytextarea1"> <label for="comments"></label> <textarea name="comments" id="comments" cols="45" rows="5" tabindex="50"></textarea> <span class="textareaRequiredMsg">Please enter your comments here.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span></p> <p> <label for="submit"></label> <input type="submit" name="submit" id="submit" value="Send Form" tabindex="50" /> </p> </form> Here is the PHP Code: <?php /* Subject and variables */ $emailSubject = 'New Email Enquiry'; $webMaster = 'enquiry@davids-photography.com'; /* Gathering data variables */ $nameField = $_POST['name']; $emailField = $_POST['email']; $stateField = $_POST['state']; $stylesField = $_POST['styles']; $commentsField = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $name <br> Email: $email <br> State: $state <br> Style: $style <br> Comment: $comments <br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); ?> Any help you can offer would be greatly appreciated. I am not looking for anything over the top, just something simple that works. Thanks David |