kikicode Posted October 15, 2008 Share Posted October 15, 2008 I am creating forms where our customers can request product quotes online. When I am gathering the information on the client, there is a field to ask them how they found out about our company. There are numerous options presented as checkboxes so they could select more than one option. Each option contains further sub-options so the client can specify details. For example: _________________________________________________________________ <input type="checkbox" name="referral_type[]" value="Internet" onclick="showrfqref('internet_referral_div');" /> Internet<br /> <span id="internet_referral_div" style="display: none"> <input type="radio" name="internet_referral" value="Google" /> Google <input type="radio" name="internet_referral" value="Yahoo" /> Yahoo! <input type="radio" name="internet_referral" value="MSN or Windows Live" /> MSN/Windows Live <input type="radio" name="internet_referral" value="GlobalSpec" /> GlobalSpec <input type="radio" name="internet_referral" value="ThomasNet" /> ThomasNet <input type="radio" name="internet_referral" value="Distributor Website" /> Distributor Website <input type="radio" name="internet_referral" value="Other" /> Other <input type="text" name="internet_referral_other_details" class="rfq" value="<? echo $_POST['internet_referral_other_details'] ?>" maxlength="50" size="11" /> <br /><br /> </span> _________________________________________________________________ When I am processing this data, it is possible for the client to select more than one referral type, each with its own set of details. I am using a foreach loop to put all of this data into one variable, called $referral_type. Here is the code I am using: _________________________________________________________________ foreach($_POST['referral_type'] as $referral_type_value) { if ($referral_type_value == 'Internet') { $referral_details = $_POST['internet_referral']; if ($referral_details == 'Other') { $referral_details .= ' - '.$_POST['internet_referral_other_details']; } } if ($referral_type_value == 'Distributor') { $referral_details = $_POST['distributor_details']; } if ($referral_type_value == 'Employee') { $referral_details = $_POST['employee_details']; } if ($referral_type_value == 'Industry Colleague') { $referral_details = $_POST['industrycolleague_details']; } if ($referral_type_value == 'Trade Show') { $referral_details = $_POST['tradeshow_details']; } if ($referral_type_value == 'Print Advertising') { $referral_details = $_POST['printad_details']; } if ($referral_type_value == 'Other') { $referral_details = $_POST['other_details']; } $referral_type .= $referral_type_value.' - '.$referral_details.'\n'; } _________________________________________________________________ The code seems to be passing the data through and into the $referral_type variable correctly, but my problem is that it is adding the word "Array" to the front of the data. The data it is returning looking like this: ArrayInternet - Google Distributor - ABC Corporation instead of this: Internet - Google Distributor - ABC Corporation I cannot figure out why it is doing this or how to prevent it from happening. Any insight you have would be much appreciated. Link to comment https://forums.phpfreaks.com/topic/128559-solved-php-foreach-loop-printing-word-array-in-front-of-my-data/ Share on other sites More sharing options...
Zhadus Posted October 15, 2008 Share Posted October 15, 2008 It seems that $referral_type is set to an array or another value at some point, since in your foreach loop you're using ".=". Try setting $referral_type = ""; before the foreach loop and see if you get the same results. Also please use the CODE tags to display your code in the future. Link to comment https://forums.phpfreaks.com/topic/128559-solved-php-foreach-loop-printing-word-array-in-front-of-my-data/#findComment-666246 Share on other sites More sharing options...
kikicode Posted October 15, 2008 Author Share Posted October 15, 2008 Also please use the CODE tags to display your code in the future. Sorry. Will do. Link to comment https://forums.phpfreaks.com/topic/128559-solved-php-foreach-loop-printing-word-array-in-front-of-my-data/#findComment-666255 Share on other sites More sharing options...
kikicode Posted October 15, 2008 Author Share Posted October 15, 2008 Your solution totally worked, Zhadus. Thanks. Link to comment https://forums.phpfreaks.com/topic/128559-solved-php-foreach-loop-printing-word-array-in-front-of-my-data/#findComment-666259 Share on other sites More sharing options...
Zhadus Posted October 15, 2008 Share Posted October 15, 2008 Glad I could help, always be wary of using ".=" without a clean slate. Link to comment https://forums.phpfreaks.com/topic/128559-solved-php-foreach-loop-printing-word-array-in-front-of-my-data/#findComment-666262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.