Forums

Dynamic Elements - How?

needshelp 05 Dec, 2011
Hey Guys,

Joomla v1.5
ChronoForms v3

My form has table of fields going horizontal with (add) button. What the add button does is clone the element and gives it new id's.

When the form is submitted I get the dynamic / cloned elements in my $_POST variable, but when the confirmation email is sent to the email defined I do not get those additional fields created. It seems the only values going through are the ones created by the form in the wizard, or fields that already exist when the page is loaded, anyway to add them to the array of values that are used when sending the email?
GreyHead 06 Dec, 2011
Hi NeedsHelp,

You'd need to have all the 'extra' names in the Email template; or more tidily to use PHP to check the submitted results and add the extra lines to the template as needed.

Bob
needshelp 06 Dec, 2011
How could I check the php code before it is sent, I mean I know it would be code needed in the before sent but what type?
GreyHead 06 Dec, 2011
Hi NeedsHelp,

It depends a bit on how you have the 'extendable' inputs setup but basically I'd look at the $_POST array to see which inputs were included there.

Bob
needshelp 06 Dec, 2011
I'm following I guess what I am wondering is how do I get the new post items into the already set post that chrono's is waiting for?

Because if I submit this code after "send email" section I can get the dynamic element values, but how do I inject them in to the $post that chrono is using?
GreyHead 06 Dec, 2011
Hi NeedsHelp,

You've lost me?

Are you talking about the 'fixed template' method - in that case you need to include all possible names in the template.

Or the 'variable' template method - in that case you'd build the template with PHP depending on the form results.

Bob
needshelp 06 Dec, 2011
A mixture basically this is what's happening.

I have an input that is being cloned (my dynamic element), when you submit, Chrono form can not see that value, or add it to the email template, but you can access it after being submitted in the get::('post') or $_POST.
GreyHead 06 Dec, 2011
Hi NeedsHelp,

Yes I understand, but that isn't the question I'm asking. ChronoForms will see it OK. The question is how you want to include the results in the Email template??

Bob
needshelp 06 Dec, 2011
We are definitely on the same page. I would love for it to be dynamic into the email template, because the cloned elements depends on how many time the user submits it. The user may add or subtract the number of cloned elements, each of course with unique name, and id, so I can't have anything set.
GreyHead 06 Dec, 2011
Hi needshelp,

OK, then the trick is to make a part of the Email template dynamic. Turn off the HTML editor in the Email setup properties box then put a PHP section into the Email template. What are the names of your dynamic inputs?

Bob
needshelp 06 Dec, 2011
They get dynamically name so for example;

name-0, name-1 etc..
GreyHead 17 Dec, 2011
Hi NeedsHelp,

As a side note the dashes in the names may cause problems. And it might be easier to use array names.

You should be able to write a PHP snippet that loops through these. Here's a very basic version:
<?php
// get the number of elements submitted
$count = 0;
WHILE ( isset($_POST['name-'.$count]) );
  $count++;
} 
// loop through the elements and show them
for ( $i = 0; $i <= $count; $i++ ) {
  echo $POST['name-'.$i];
}
?>
Not tested and may need debugging!

Bob
This topic is locked and no more replies can be posted.