Lodius2000 Posted May 12, 2008 Share Posted May 12, 2008 so after i click the Select color button I see "Warning: implode() [function.implode]: Bad arguments. on line 26" and my select menu and select color button are redisplayed if anyone could tell me why this is happening or a different way to display errors it would be greatly appreciated. I have used this syntax in other form processing scripts but never with a select menu, and they are just sooooo different than the other form types <?php require 'formhelpers.php'; session_start(); $colors = array('#ffffff' => 'White', '#ff0000' => 'Red', '#00ff00' => 'Green', '#0000ff' => 'Blue', '#000000' => 'Black'); if($_POST['_submit_check']){ if($form_errors = validate_form()){ show_form($form_errors); } else { process_form(); } } else { show_form(); } function show_form($errors = '') { if ($errors){ $error_text = '<ul><li>'; //below is line 26 $error_text .= implode('</li><li>', $errors); $error_text .= '</li></ul>'; } else { $error_text =''; } print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; //begin the unique form print 'Color: '; input_select('color', $defaults, $GLOBALS['colors']); print '<br />'; input_submit('submit', 'Select Color'); print '<input type="hidden" name="_submit_check" value="1" />'; print '</form>'; } function validate_form(){ $errors = array(); // color selected must be valid if (! array_key_exists($_POST['colors'], $GLOBALS['colors'])){ $errors = 'please enter a valid color.'; } return $errors; } function process_form(){ $_SESSION['color'] = $_POST['color']; print "your favorite color is " . $_GLOBALS['colors'][$_SESSION['color'] ]; } ?> and the relevant part of formhelpers.php <?php //print a select menu function input_select($element_name, $selected, $options, $multiple = false){ //print out the <select> tag print '<select name="' . $element_name; // if multiple choices are permitted, add the multiple attribute // and add a [] to the end of the tag name if ($multiple){ print '[]" multiple="multiple'; } print '">'; //set up the list of things to be selected $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val){ $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } //print out the <option> tags foreach ($options as $option=>$label) { print '<option value="' . htmlentities($option) . '"'; if ($selected_options[$option]){ print ' selected="selected"'; } print '>' . htmlentities($label) . '</option>'; } print '</select>'; } ?> thanks a bunch for your help Link to comment https://forums.phpfreaks.com/topic/105211-solved-warning-implode-functionimplode-bad-arguments/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.