Joined Data & Emails

sgorney

Member
Hi everyone:

I'm struggling a bit with emailing joined data. I have a databasejoin element that connects to some Sobi tables. The element shows a checkbox list of all the records in sobi.

This is all working great. The problem is trying to email the list of selected sobi items (displayed as a checkbox) to an email. I'm using my own email template, but it has this code for pulling joined data:

$joindata = $this->data['join'];

foreach (array_keys($joindata) as $joinkey) :
$keys = array_keys($joindata[$joinkey]);
$length = count($joindata[$joinkey][$keys[0]]);
for ($i = 0; $i < $length; $i++) :
echo '<tr><td colspan="2"><h3>record ' . $i . '</h3></td></tr>';
foreach ($keys as $k) :
echo '<tr><td>' . $k . '</td><td>' . $this->data['join'][$joinkey][$k][$i] . '</td></tr>';
endforeach;
endfor;
endforeach;

This comes directly from the debug.php file. When I receive this email, the output this code is generating is:

Code:
Join data

Below out puts the form's join data one record at a time:

record 0

tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw	450
tbl_brochure_request_form_repeat_entry_selects___entry_selects	<
record 1

tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw	74
tbl_brochure_request_form_repeat_entry_selects___entry_selects	u

Not sure what is causing the problem here. It's outputting the proper record IDs, but not the labels. When I do a print_r($joindata) the labels *do* come through correctly, but of course parsing through those arrays is a pain.

Any ideas on how to get this operating correctly? Thanks!

(PS: Github update Nov 1 2012)
 
could you post the html markup that the template generates?

to do that add

PHP:
exit;

to the bottom of the email template and then submit the form. It will then bomb out, after having generated the html which you should be able to then use the browsers view source to see and paste back in this thread.
 
Code:
<style type="text/css">
	span {width: 150px; font-weight: bold;}
</style>
<table>
<h3>Your Shipping Information</h3>
<ul>
	<li>
		<span class="heading">First Name</span>
		{tbl_brochure_request_form___first_name}
	</li>
	<li>
		<span class="heading">Last Name</span>
		{tbl_brochure_request_form___last_name}
	</li>
	<li>
		<span class="heading">Email</span>
		{tbl_brochure_request_form___email}
	</li>
	<li>
		<span class="heading">Address</span>
		{tbl_brochure_request_form___address}
	</li>
	<li>
		<span class="heading">City / Town</span>
		{tbl_brochure_request_form___city_town}
	</li>
	<li>
		<span class="heading">State</span>
		{tbl_brochure_request_form___state}
	</li>
	<li>
		<span class="heading">Zip</span>
		{tbl_brochure_request_form___zip}
	</li>
	<li>
		<span class="heading">Telephone</span>
		{tbl_brochure_request_form___telephone}
	</li>
	<li>
		<span class="heading">Fax</span>
		{tbl_brochure_request_form___fax}
	</li>
	<li>
		<span class="heading">Company</span>
		{tbl_brochure_request_form___Company}
	</li>
</ul>

	Real Estate Broker: {tbl_brochure_request_form___real_estate}<br />
	Learned About Us:	{tbl_brochure_request_form___learned_about}<br />
	Entry Selection


<h2>Join data</h2>
<p>Below out puts the form's join data one record at a time:</p>
<table>


<tr><td colspan="2"><h3>record 0</h3></td></tr><tr><td>tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw</td><td>431</td></tr><tr><td>tbl_brochure_request_form_repeat_entry_selects___entry_selects</td><td><</td></tr><tr><td colspan="2"><h3>record 1</h3></td></tr><tr><td>tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw</td><td>400</td></tr><tr><td>tbl_brochure_request_form_repeat_entry_selects___entry_selects</td><td>u</td></tr>

It's strange. That 'u' and '<' lingering about. I'm wondering if it is a part of the UL element for the select list. Strange it's not outputting correctly!
 
does any of your data contain characters like '<' ?

perhaps try :

PHP:
$joindata = $this->data['join'];

foreach (array_keys($joindata) as $joinkey) :
    $keys = array_keys($joindata[$joinkey]);
    $length = count($joindata[$joinkey][$keys[0]]);
    for ($i = 0; $i < $length; $i++) :
        echo '<tr><td colspan="2"><h3>record ' . $i . '</h3></td></tr>';
        foreach ($keys as $k) :
            echo '<tr><td>' . $k . '</td><td>' . htmlspecialchars($this->data['join'][$joinkey][$k][$i]) . '</td></tr>';
        endforeach;
    endfor;
endforeach;
 
Hi Rob:

No go on this. (Sorry it's been so long since I've updated this thread - been traveling).

Here's a datadump of the $joindata variable:

Array
(
[10] => Array
(
[tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw] => Array
(
[0] => 74
)

[tbl_brochure_request_form_repeat_entry_selects___entry_selects] => <ul class="fabrikRepeatData"><li>Buckeye Ranch</li></ul>
)

)

And this is what comes through the email:

Code:
record 0

tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw	417
tbl_brochure_request_form_repeat_entry_selects___entry_selects	<
record 1

tbl_brochure_request_form_repeat_entry_selects___entry_selects_raw	455
tbl_brochure_request_form_repeat_entry_selects___entry_selects	u
 
Hey Chad,

Got you on Skype. Just to remind myself of our conversation, I'm pretty sure it's to do with your loop logic, and the fact that the raw is an array, but the formatted value isn't. So somewhere in there you are treating the formatted value (a string) as an array, with a [0] index, which is why it's only printing the first character, which is what happens when you access a string in an array context, you get the [n]'th character.

-- hugh
 
Back
Top