ThatGuyRay Posted March 24, 2017 Share Posted March 24, 2017 Pulling my hair out trying to get checkbox and a selector values into my email. The only email results I recieve are: Name/Email/Website/Message I dont know what Im missing to get the Checkbox values submitted. Ive included a link and attached the files for reference. http://iinobe.com/formTest/contact.html Any insight, assistance or resources that would help solve this issue would be greatly appreciated. Thanks Ray BASIC CODE: <input type="checkbox" id="b1" name="vehicle[]" value="Bike">I have a bike<br> <input type="checkbox" id="b1" name="vehicle[]" value="Car">I have a car <input type="checkbox" id="b1" name="vehicle[]" value="Walk">I walk <select id="choose"> <option>1</option> <option>2</option> <option>3</option> </select> My additions to PHP: $b1 = implode(', ', $_POST['b1'] ); $choose = $_POST['choose']; \n\nType: $b1 \n\nChoice: $choose Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/ Share on other sites More sharing options...
benanamen Posted March 24, 2017 Share Posted March 24, 2017 (edited) What makes you think ID's are in the POST array? The checkbox array is vehicle and the Select is missing the name attribute so nothing from that will be in the POST array. Edited March 24, 2017 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544542 Share on other sites More sharing options...
Psycho Posted March 24, 2017 Share Posted March 24, 2017 To add to benanamen's response, it is not valid HTML markup to have multiple elements with the same id as you have with the checkboxes. The id for each element must be unique. <select id="choose" name="choose"> $vehicles = implode(', ', $_POST['vehicles'] ); $choose = $_POST['choose']; Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544546 Share on other sites More sharing options...
ThatGuyRay Posted March 24, 2017 Author Share Posted March 24, 2017 Thanks for the response. I am a definitely a novice. Im using a pre-existing form from a template and the template developer made the following suggestion: " Give unique ids to the inputs and use the ids on global variable (for ex. $_POST['your_id']). " Ive made the id edits as suggested, but still no results in email: <input type="checkbox" id="b1" name="vehicle[]" value="Bike">I have a bike<br> <input type="checkbox" id="b2" name="vehicle[]" value="Car">I have a car <input type="checkbox" id="b3" name="vehicle[]" value="Walk">I walk <select class="form-control" name="choose" id="choose"> <option>1</option> <option>2</option> <option>3</option> </select> PHP: <?php if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $vehicles = implode(', ', $_POST['vehicles'] ); $choose = $_POST['choose']; $name = $_POST['name']; $email_address = $_POST['email']; $website = $_POST['website']; $message = $_POST['message']; // Create the email and send the message $to = 'biz@iinobe.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to. $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form. \n\n"."Here are the details: \n\nName: $name \n\nType: $vehicles \n\nChoice: $choose \n\nEmail: $email_address \n\nWebsite: $website \n\nMessage:\n$message"; $headers = "From: noreply@gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com. $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true; ?> Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544552 Share on other sites More sharing options...
ginerjm Posted March 24, 2017 Share Posted March 24, 2017 If you turned on php error checking you might see why. It is 'vehicle', not 'vehicles'. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544554 Share on other sites More sharing options...
Jacques1 Posted March 24, 2017 Share Posted March 24, 2017 “vehicles” isn't the same as “vehicle”. Yes, you have to be exact. In any case, it's time for you to learn basic debugging steps. Forget about the e-mails. Right now, you cannot even assemble the message correctly, so it's nonsensical to add complex mail sending logic which may introduce even more errors. Remove the mail() call for now. Learn how to inspect variables with var_dump(). For example, var_dump($_POST) will tell you exactly what the $_POST array contains (and what it doesn't contain). When you're more experienced, check out professional debuggers like XDebug. This will save you a lot of time. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544555 Share on other sites More sharing options...
benanamen Posted March 24, 2017 Share Posted March 24, 2017 You STILL have not added any VALUES to your Select. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544556 Share on other sites More sharing options...
ThatGuyRay Posted March 24, 2017 Author Share Posted March 24, 2017 Thanks. I have actually updated the code - but no results: <input type="checkbox" id="b1" name="vehicle[]" value="Bike">I have a bike<br> <input type="checkbox" id="b2" name="vehicle[]" value="Car">I have a car <input type="checkbox" id="b3" name="vehicle[]" value="Walk">I walk <select class="form-control" name="choose" id="choose" form="sentMessage"> <option value="uno">1</option> <option value="dos">2</option> <option value="tres">3</option> </select> This may be over my head at this point. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544557 Share on other sites More sharing options...
ginerjm Posted March 24, 2017 Share Posted March 24, 2017 Stop showing us tidbits of your code. Show us the WHOLE FORM and then show us the logic that is grabbing the inputs and how you are displaying the results. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544558 Share on other sites More sharing options...
Jacques1 Posted March 24, 2017 Share Posted March 24, 2017 Reading the replies also helps. As I've already told you, programming by trial-and-error doesn't work. Remove the parts which aren't relevant for the problem (like the mail stuff), learn how to use var_dump() and then analyze the problem systematically. Quote Link to comment https://forums.phpfreaks.com/topic/303531-select-checkbox-values-don%E2%80%99t-show-up-in-submitted-form/#findComment-1544559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.