joemamahunt Posted February 27, 2008 Share Posted February 27, 2008 A little bit stuck and confused.. Form: ... <label><input type="radio" id="radio1" name=”radio1” value=”1” /> 1</label> <label><input type="radio" id="radio1" name=”radio1” value=”2” /> 2</label> <label><input type="radio" id="radio1" name=”radio1” value=”3” /> 3</label> <label><input type="radio" id="radio1" name=”radio1” value=”4” /> 4</label> ... <label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="english" /> English</label> <label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="russian" /> Russian</label> <label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="ukrainian" /> Ukrainian</label> <label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="romanian" /> Romanian</label> <label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="spanish" /> Spanish</label> <label><input type="checkbox" id="lang_studied[]" name="lang_studied[]" value="other" /> Other</label> ... Simplified process form: <?php // Pick up the form data and assign it to variables $radio1 = $_POST['radio1']; $lang_studied = $_POST['lang_studied']; $message = "$radio1 $lang_studied"; // Send the mail using PHPs mail() function mail($message); // Redirect header("Location: submitted.php"); ?> ??? Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/ Share on other sites More sharing options...
drisate Posted February 27, 2008 Share Posted February 27, 2008 in this case lang_studied[] is an array so to send it use foreach ($_POST['lang_studied'] as $value) ... ... Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-477684 Share on other sites More sharing options...
joemamahunt Posted February 27, 2008 Author Share Posted February 27, 2008 Then I get: Warning: Invalid argument supplied for foreach() And about the radio buttons, how do I have the selected option's text show up? I figured it would automatically if it is in it's label.. no? Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-477693 Share on other sites More sharing options...
DarkerAngel Posted February 27, 2008 Share Posted February 27, 2008 Try this instead $languages = implode(', ', $_POST['lang_studied']); It will give you a string with all the checked boxes' values separated by a comma. Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-477702 Share on other sites More sharing options...
joemamahunt Posted February 27, 2008 Author Share Posted February 27, 2008 Warning: implode() [function.implode]: Bad arguments. Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-477722 Share on other sites More sharing options...
cyrixware Posted February 27, 2008 Share Posted February 27, 2008 <input type="hidden" name="Item[]" value="<?=$r['Item'];?>"> <?php if($_REQUEST['Submit'] == "Submit") { include("../connDB.php"); $Items = $_REQUEST['Item']; for ($x = 0 ; $x < $i ; $x++) { $sql_add = "INSERT INTO studans (SubItems)VALUES("'" . $_REQUEST['Item'][$x] . "')"; $q_add = mysql_query($sql_add); } ?> please modify this.... Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-477788 Share on other sites More sharing options...
roopurt18 Posted February 27, 2008 Share Posted February 27, 2008 You're also using your labels wrong: <input type="radio" id="radio1" name="radio1" /> <label for="radio1">1</label> Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-477814 Share on other sites More sharing options...
joemamahunt Posted February 27, 2008 Author Share Posted February 27, 2008 ^ thanks - fixed it. <input type="hidden" name="Item[]" value="<?=$r['Item'];?>"> <?php if($_REQUEST['Submit'] == "Submit") { include("../connDB.php"); $Items = $_REQUEST['Item']; for ($x = 0 ; $x < $i ; $x++) { $sql_add = "INSERT INTO studans (SubItems)VALUES("'" . $_REQUEST['Item'][$x] . "')"; $q_add = mysql_query($sql_add); } ?> please modify this.... Whatever this is supposed to do, I'm not using a MySQL database, I'm just emailing the form. I got this working: $languages = implode(', ', $_POST['lang_studied']); But in my email it just shows "Array". And the radio choice is still not showing. Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-478602 Share on other sites More sharing options...
roopurt18 Posted February 28, 2008 Share Posted February 28, 2008 joemamahunt I'm going to give you the best advice possible for fixing a broken program: Get more information. 1) Read carefully any error messages 2) If there are no error messages, add code to print error messages (such as echo()'ing mysql_error()) 3) VERIFY your data. Make sure the variables contain what you expect them to contain. This prevents you from using arrays as strings, strings as numbers, etc. As a continuation of #3, the best way to verify your data is to send it as output. Here is a simple little function, that you can expand upon if you wish, to echo your data so that it's easy to read: function debug_echo($val){ $val = print_r($val, true); echo "<pre style='text-align: left;'>{$val}</pre>"; } Add that to your script and at the very top do: debug_echo($_POST); What prints when you submit your form? Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-478628 Share on other sites More sharing options...
joemamahunt Posted February 28, 2008 Author Share Posted February 28, 2008 This gets printed: Array ( ) I've checked the code too many times and it should be working fine to my understanding. Basically all I'm using is what I have quoted in my first post. I have a bunch of simple variables that just get posted, but they are not listed as they are unimportant and work as they should. (I've checked them all) All in all, I'm just trying to email myself the form inputs and selections on submit, and the inputs get sent fine, but the radio and checkboxes do not. Radio selection is not showing up anything, while currently the checkbox selections are just showing the word "Array". Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-478689 Share on other sites More sharing options...
roopurt18 Posted February 28, 2008 Share Posted February 28, 2008 If that's what is inside of $_POST when you submit the form then something is wrong elsewhere in your code or you did not check any of the boxes on your form. Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-478704 Share on other sites More sharing options...
joemamahunt Posted February 28, 2008 Author Share Posted February 28, 2008 Got the checkboxes to work. Human error on my side. (forgot to switch the variable name) Got the radio buttons to work by deleting and re entering the quotation keys. I didn't change anything, just deleted and re typed in the following key for the name & values: " Weird. Thanks for all the help guys. Link to comment https://forums.phpfreaks.com/topic/93250-form-processing-checkboxes-radio-buttons/#findComment-478745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.