napsburypark Posted March 24, 2010 Share Posted March 24, 2010 Hi Folks. A quick question. I am trying out the fcbkcomplete script which will be great on a new school website I am working on however when it sends the form field it sends it as select2[] so if I were using the GET method I see in the address bar submit.php?select2[][email protected] however when i try and capture the select2[] php just says 'array' Any ideas? Thank you Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/ Share on other sites More sharing options...
napsburypark Posted March 24, 2010 Author Share Posted March 24, 2010 Sorry should have said I am trying to capture it by the following: <?php echo $_GET["select2"]; ?> and have tried <?php echo $_GET["select2[]"]; ?> thanks Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031260 Share on other sites More sharing options...
prometheos Posted March 24, 2010 Share Posted March 24, 2010 it might be because your only echoing the array and not a specific element in it. you could try looping through and printing out every element or a specific 1 try <?php $arr = $_GET['select2']; foreach( $arr as $a){ echo $a; } ?> Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031269 Share on other sites More sharing options...
napsburypark Posted March 24, 2010 Author Share Posted March 24, 2010 Genius! Thank you Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031273 Share on other sites More sharing options...
prometheos Posted March 24, 2010 Share Posted March 24, 2010 you're welcome Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031275 Share on other sites More sharing options...
napsburypark Posted March 24, 2010 Author Share Posted March 24, 2010 actually I now have another little problem. I need the form to send via PHPMAIL - I am using the following. <?php $to = $arr = $_GET['select2']; foreach( $arr as $a){ echo $a;}; $subject = $_REQUEST['Subject'] ; $message = "This is an online form enquiry sent from the website. Your Name: ".$_REQUEST['parent']." Your Telephone: ".$_REQUEST['telephone']." Your Message: ".$_REQUEST['message']." This email was automatically generated. Thank You"; $from = $_REQUEST['email'] ; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo ""; ?> but i get the following error now: Warning: mail() expects parameter 1 to be string, array given in /home/marlb/public_html/About/form/submit1.php on line 33 Any ideas? Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031278 Share on other sites More sharing options...
napsburypark Posted March 24, 2010 Author Share Posted March 24, 2010 Any ideas? Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031303 Share on other sites More sharing options...
greatstar00 Posted March 24, 2010 Share Posted March 24, 2010 as prometheos said, $arr, or $_GET['select2[]'], both of these are array if u dont know what is array, read http://php.net/manual/en/language.types.array.php so, u access $arr[0] or $arr[0] $arr= $_GET['select2[]']; $to=$arr[0]; NOT the following $to = $arr <<< WRONG!!!!!!!!!!!!!!!!!!!!!!!!!!!! in the wrong case, u get this $arr= array('something', 'something1', 'something'); in the right case u get $arr='something'; Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031307 Share on other sites More sharing options...
napsburypark Posted March 24, 2010 Author Share Posted March 24, 2010 Okay got it. Thank you I have this working now. I have just one more query. If the form submits more than one email address it will post the following: submit.php?select2[][email protected]&select2[][email protected] however PHPMail just sees this as to: [email protected]@email.com how can I make the following code break those two email addresses up? <?php $arr = $_REQUEST['select2']; foreach( $arr as $a){ } ?> <?php $to=$arr[0]; $subject = $_REQUEST['Subject'] ; $message = "This is an online form enquiry sent from the Website. The details of which are below. Your Name: ".$_REQUEST['parent']." Your Telephone: ".$_REQUEST['telephone']." Your Message: ".$_REQUEST['message']." This email was automatically generated. Thank You"; $from = $_REQUEST['email'] ; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo ""; ?> I know I am asking a lot but I am new to PHP and just need to get this PHP element working. Thank you in advance for all your help. Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031332 Share on other sites More sharing options...
prometheos Posted March 24, 2010 Share Posted March 24, 2010 try using the explode function http://ie.php.net/manual/en/function.explode.php Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031347 Share on other sites More sharing options...
napsburypark Posted March 25, 2010 Author Share Posted March 25, 2010 Any ideas? Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031585 Share on other sites More sharing options...
ignace Posted March 25, 2010 Share Posted March 25, 2010 actually I now have another little problem. I need the form to send via PHPMAIL - I am using the following. <?php $to = $arr = $_GET['select2']; foreach( $arr as $a){ echo $a;}; $subject = $_REQUEST['Subject'] ; $message = "This is an online form enquiry sent from the website. Your Name: ".$_REQUEST['parent']." Your Telephone: ".$_REQUEST['telephone']." Your Message: ".$_REQUEST['message']." This email was automatically generated. Thank You"; $from = $_REQUEST['email'] ; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo ""; ?> but i get the following error now: Warning: mail() expects parameter 1 to be string, array given in /home/marlb/public_html/About/form/submit1.php on line 33 Any ideas? This code is find all you need to change is: mail($to, .. to mail(implode(',', $to), .. Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031588 Share on other sites More sharing options...
oni-kun Posted March 25, 2010 Share Posted March 25, 2010 Any ideas? Why aren't you doing anything with the array? $arr = $_GET['select2']; $contacts = implode(', ', $arr); //e-mail1, e-mail2 in php's mail() acceptable format mail Link to comment https://forums.phpfreaks.com/topic/196413-php-array-help-please/#findComment-1031590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.