Forums

Format email from multiple arrays

chriso0258 22 May, 2012
I am sending three arrays to the email action (first_name, last_name, rating). I have the email template listed as:

<tr>
	<td>
		Name and Rating: 
	</td>
	<td>
		{first_name} {last_name} {rating}
	</td>
	</tr


The email returns the following:
Name and Rating: 	Firstname1, Firstname2, Firstname2 Lastname1, Lastname2, Lastname2 865,520 , 1500


As you can see, the array is being sent just fine. Is there a way I can format the email so it appears like this:


Firstname1 Lastname1 865
Firstname2 Lastname2 520
Firstname3 Lastname3 1500


I wouldn't even mind if the simplest way is to put them all on one line, but in the order shown.

Thanks.
GreyHead 23 May, 2012
Hi chriso0258 ,

You can add a Custom Code action before your Handle arrays action and add code like this:
<?php
$name_and_rating = array();
foreach ( $form->data['first_name'] as $k => $v ) {
  $name_and_rating[] = "{$v} {$form->data['last_name'][$k]} {$form->data['rating'][$k]}";
}
$form->data['name_and_rating'] = implode("\n", $name-and_rating);
?>
Then use {name_and_rating} in your email template.

Bob
chriso0258 23 May, 2012
Thanks Bob. Since my post, I changed the input to what I think is a multidimensional array instead.

  <TR>
    <TD> <input type="text" name="mbr_info[][first_name]"/></TD>
    <TD> <input type="text" name="mbr_info[][last_name]"/></TD>
    <TD> <input type="text" name="mbr_info[][rating]"/></TD>
  </TR>


I think I still need to do what you have suggested, but I'm not sure how to format the foreach because of the new array structure.
chriso0258 24 May, 2012
Please disregard my last post. Turns out I can use the mbr_info[] directly using the Handle Arrays action. Thank you Bob for your input. It has been a help (as usual).😀
This topic is locked and no more replies can be posted.