dewey_witt Posted November 25, 2007 Share Posted November 25, 2007 Here is some code..... I need to add the values only to a form input(text) on the page submitted too. I've done this a million times yet i keep getting the word "array" in front of the values as such...... <input name="mail[]" type="checkbox" value="Value 1" /> <input name="mail[]" type="checkbox" value="Value 2" /> <input name="mail[]" type="checkbox" value="Value 3" /> Now this is what Im useing to retreive this data: $mail = $_POST['mail']; if(!empty($mail)) { foreach($mail as $key => $val) { $mail .= "". $val .", "; } } $stringa="$mail, "; $stringa=trim( ereg_replace( "[^@_.[:space:]a-zA-Z0-9]", " ", $stringa ) ); echo $stringa; $send = "$stringa, "; This is the result Im getting [email protected], [email protected], For one I'd love to know why...Imma question asker and two anyone see wtf Im doing wrong? O.o Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/ Share on other sites More sharing options...
xyn Posted November 25, 2007 Share Posted November 25, 2007 use $var = implode(",", $mail); Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/#findComment-398422 Share on other sites More sharing options...
dewey_witt Posted November 25, 2007 Author Share Posted November 25, 2007 OK tried that tells me that it is a bad argument. O.o all i want is the word "array to go away *crys like a lil bi*ch* Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/#findComment-398425 Share on other sites More sharing options...
dewey_witt Posted November 25, 2007 Author Share Posted November 25, 2007 Noone? :'( Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/#findComment-398435 Share on other sites More sharing options...
xyn Posted November 25, 2007 Share Posted November 25, 2007 Looks to me liek your trying to get this 1,2,3 from your fields which. $var = implode(",", $_POST[mail]); is the best option. however try... $mail =(is_array($_POST[mail]))? implode(",", $_POST[mail]):$_POST[mail]; if all fails, try this: $count = count($_POST[mail]); for($i=0;$i<$count;$i++) $mail.= ($i == $count)? $_POST[mail][$i]:$_POST[mail][$i].","; Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/#findComment-398439 Share on other sites More sharing options...
hitman6003 Posted November 25, 2007 Share Posted November 25, 2007 You are assigning $mail to be equal to an array, then you are appending a string onto the end of that. When php converts an array into a string(which is happening when you are appending a string to the end of $mail, which to start with is an array), it is converted to simply "Array". You can get rid of the "Array" at the beginning by simply not using $mail as the variable to store the $_POST['mail'] array. In fact, why reassign that array to another variable anyway? Use the recommendation by xyn: $mail =(is_array($_POST['mail']))? implode(",", $_POST['mail']):$_POST['mail']; Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/#findComment-398468 Share on other sites More sharing options...
dewey_witt Posted November 26, 2007 Author Share Posted November 26, 2007 AWSOME! That worked! Yoy guys are awsome! Quote Link to comment https://forums.phpfreaks.com/topic/78725-solved-loopsing-threw-checkbox-array/#findComment-399436 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.