No show in mailtemplate from dynamic, cloned, add-on fields

franky2nl 19 Mar, 2009
Dear people,

I like to work with CF. I don't do it for a long time yet.This is my problem;

I'm developing a bookingform. People who decide to book a trip can fill up this form. The main passenger fills up all the information passenger 2 and further only have to supply their first, last name, date of birth, nationality and city.

Normal you can supply the data through fields - on the websiteform - like (for example) NAME="NAME". Then in your mailtemplate you get this information by using {NAME}.

In my form i'm also using the option "other passengers". Every time you add a new passenger - by using a button - , a new line shows up where you can fill up the needed information for the next passenger. One thing you have to fillup is the first name for example. Where you fill up the name, the form is using the field; name="deelnemer[name][]". It's written in this way because you can clone this field. But if I write it in my mailtemplate like - {deelnemer[name][]} - then it doesn't show the name of the passenger.

I hope it's to understand what is written below here, because most of it is dutch.

This is a part of the (site) code:

</DIV></fieldset><BR>
<fieldset><legend><b>OVERIGE DEELNEMERS</b></legend>
<table id="deelnemer">
<thead>
<tr id="headerdeelnemer" style="display: none">
<th class="contentblock">Voor- en achternaam</th>
<th class="contentblock">Geboortedatum</span></th>
<th class="contentblock">Geslacht</th>
<th class="contentblock">Woonplaats</th>
</tr></thead>
<tbody>
<tr id="templatedeelnemer" style="display: none">
<td><input type="text" name="deelnemer[naam][]" value="" /></td>
<td><input type="text" name="deelnemer[geboortedatum][]" value="" /></td>
<td><select name="deelnemer[geslacht][]"><option value="m">Man</option>
<option value="f">Vrouw</option>
</select></td>
<td><input type="text" name="deelnemer[plaats][]" value="" /></td></tr>
</tbody></table>
<input type="button" name="addrowdeelnemer" value="Voeg deelnemer toe" id="addrowdeelnemer" /></fieldset><br>
<input type="submit" name="submit" value="Aanvraag versturen" id="submit" />
</form>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#addrowdeelnemer').click(function() {
//rij toevoegen op basis van template
$('#deelnemer').append($($('#templatedeelnemer').clone(true)).attr('id','').show());
$('.delbtn').click(function(){
$(this).parents('tr').remove();
});
});
$('#deelnemer').append($($('#headerdeelnemer').clone(true)).attr('id','').show());
$('#addrowdeelnemer').trigger('click');
});
</script></div>
</div>
</div>
</div>


This is apart of the (mailtemplate) code:

<fieldset><legend><b>Overige deelnemers</b></legend>
<table>
<thead>
<tr>
<th>Voor- en achternaam</th>
<th>Geboortedatum</span></th>
<th>Geslacht</th>
<th>Woonplaats</th>
</tr></thead>
<tbody>
<tr>
<td>{deelnemer[naam][]}</td>
<td>{deelnemer[geboortedatum][]}</td>
<td>{deelnemer[geslacht][]}</td>
<td>{deelnemer[plaats][]}</td></tr>
</tbody></table>


Does anybody know how I can solve this problem? I hope that somebody can help me because I really want to use cloned fields.

With regards,

Frank
GreyHead 19 Mar, 2009
Hi franky2nl,

I don't believe that the {. . .} syntax will work with arrays. But you can still access all of the form data using getVar something like this
<?php
$deelnemer =& JRequest::getVar('deelnemer','', 'post');
?>
. . .
<td><?php echo $deelnemer['name'][0]; ?></td>
. . .
Not tested and will need debugging.

Bob
franky2nl 19 Mar, 2009
Hi Bob,

First of all, thanks for the quick responding!

The problem is that I don't understand so much from PHP. So what you wrote here doesn''t say so much to me. I will try to see what it does. Isn't there anonther solution to manage such kind of form? It's the first step on developing this form so everything is possible and can be changed.

More information about this 'addrow' script;
It's written in Jquery and it comes along with a js-file.

First I will try to something with the code you gave me.

To be continued...

With regards,

Frank
franky2nl 20 Mar, 2009
Hi Bob,

I tried to do something with the code but i don't understand it. My knowledge of PHP it to less😟 . But I remember that I have a form which has a similar PHP code. I will now show this example because it is a little bit easier (for me :wink: ) to understand. But also I think it's much easier to make it work.

The form is working and the mail is showing one field; 'Aanhef'. I've changed the form from one inputfield (Aanhef) to several fields (Naam)(Geboortedatum)(Nationaliteit). How can I change the PHP code in the mailtemplate so that the mail will show all the fields, next to eachother?

First the form:

<SCRIPT type=text/javascript>
var counter = 1;
var limit = 5;
function addInput(divName){
     if (counter == limit)  {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else {
          var newdiv = document.createElement('div');
          newdiv.innerHTML = "Deelnemer " + (counter + 1) + " <br><input type='text' name='Aanhef[]'> <input type='text' name='Naam[]'> <input type='text' name='Geboortedatum[]'> <input type='text' name='Nationaliteit[]'>";
          document.getElementById(divName).appendChild(newdiv);
          counter++;
     }
}
</script>


<script src="/wp-includes/js/addInput.js" language="Javascript" type="text/javascript"></script>
<form method="POST">
     <div id="dynamicInput">
		 Deelnemer 2
		 <table border="0">
          <tr>
	       <td>Dhr/Mevr:</td>
	       <td>Voor- en achternaam:</td>
	       <td>Geboortedatum:</td>
	       <td>Nationaliteit:</td>
          </tr>
          <tr>
	       <td><input type="text" name="Aanhef[]">
		   <td><input type="text" name="Naam[]"></td>
	       <td><input type="text" name="Geboortedatum[]"></td>
	       <td><input type="text" name="Nationaliteit[]"></td>
          </tr>
         </table> 
	</div>
     <br><input type="button" value="Voeg nog een deelnemer toe" onClick="addInput('dynamicInput');">
</form>


Here is the PHP code which i put in my mailtemplate (this has to be changed):

<?php
$Aanhef = $_POST["Aanhef"];
foreach ($Aanhef as $eachInput) {
     echo $eachInput . "<br>";
}
?>



I think this one is easier to solve, I hope :?

With regards,

Frank
Max_admin 20 Mar, 2009
Hi Frank,

remove the PHP in the email template and write:

{Naam}{Geboortedatum}{Nationaliteit}


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
franky2nl 20 Mar, 2009
Hi Max,

Thank you for your respond.

Aha, now I can use the tags {} again.

But how can I make it that the emailtemplate shows it in this way, when for example 3 passenger subscribe for a trip (i want to sent a copy of the also to the passengers):

passenger 1{aanhef}
passenger 1{Naam}
passenger 1{Geboortedatum}
passenger 1{Nationaliteit}

passenger 2{aanhef}
passenger 2{Naam}
passenger 2{Geboortedatum}
passenger 2{Nationaliteit}

passenger 3{aanhef}
passenger 3{Naam}
passenger 3{Geboortedatum}
passenger 3{Nationaliteit}

Know it is shown in this way:

passenger 1{aanhef} passenger 2{aanhef} passenger 3{aanhef} passenger 1{Naam} passenger 2{Naam} passenger 3{Naam} passenger 1 {Geboortedatum} etc.

Do you know a solution for this problem?

Greetings,

Frank
GreyHead 20 Mar, 2009
Hi franky2nl,

Add some tags to the html -
<p>passenger 1{aanhef}<br />
passenger 1{Naam}<br />
passenger 1{Geboortedatum}<br />
passenger 1{Nationaliteit}</p>
You may need to use the html view in the Template editor to see these.

Bob
franky2nl 21 Mar, 2009
Hi Bob, Max,

I know that I have to work with tags now, but for 1 passenger is no problem but every field can contain several values. I already tried to place it in a table with this result for only one passenger:


Aanhef: Naam: Geboortedatum: Nationaliteit:
{aanhef} {Naam} {Geboortedatum} {Nationaliteit}


But if add 3 passengers you get this, all values placed in one long row:

Aanhef: Naam: Geboortedatum: Nationaliteit:
{aanhef}(3x) {Naam}(3x) {Geboortedatum} (3x){Nationaliteit}(3x)


And I want to have it in this way:

passenger#1 aanhef: {aanhef}
passenger#1 naam: {Naam}
passenger#1 geboortedatum: {Geboortedatum}
passenger#1 nationaliteit: {Nationaliteit}

passenger#2 aanhef: {aanhef}
passenger#2 naam: {Naam}
passenger#2 geboortedatum: {Geboortedatum}
passenger#2 nationaliteit: {Nationaliteit}

passenger#3 aanhef: {aanhef}
passenger#3 naam: {Naam}
passenger#3 geboortedatum: {Geboortedatum}
passenger#3 nationaleit: {Nationaliteit}



or maybe it's nicer to in this way;

Aanhef: Naam: Geboortedatum: Nationaliteit:
passenger#1 {aanhef} {Naam} {Geboortedatum} {Nationaliteit}
passenger#2 {aanhef} {Naam} {Geboortedatum} {Nationaliteit}
passenger#3 {aanhef} {Naam} {Geboortedatum} {Nationaliteit}


But I'm afraid none of those two options is possible by only using {aanhef} {Naam} {Geboortedatum} {Nationaliteit}😟

I hope there is an solution for this problem.

Frank
GreyHead 21 Mar, 2009
Hi franky2nl,

OK, then you are going to need to abandon the tags and resort to plain PHP. Test this in the Email template:
<?php
$result_array = array();
$field_array = array( 'aanhef', 'Naam', 'Geboortedatum', Nationaliteit );
// get the results
foreach ( $field_array as $field) {
 $result_array[$field] = JRequest::getVar($field, '', 'post);
} 
// get the number of results
$count = count($results_array['aanhef']);
// output the results
for ( $i = 1; $i <= $count; $i++ ) {
  // only out put if Naam has a value
  if ( $field_array['Naam'][$i] ) {
    // output a result block
    echo "<div>";
    foreach ( $field_array as $field ) {
      echo $field[$i]."<br />";
      }
  echo "</div>";
  }
}
?>
Not tested and will probably need debugging

You'll need to turn off the HTML Template editor in the Email Setup properties to be able to do this.

Bob
franky2nl 21 Mar, 2009
Hi Bob,

First, thanks for the reply. It's difficult (at least for me :wink:) to solve this problem. I appreciate that you guys want to help everybody on this forum to find a solution for all kind of problems. My experience on dutch forums is worse. One thing is for sure, if we manage to get this working I will make an translation from the complete form in English and will place it here among the other examples so that other people can use it😀 . It's very hard to find this kind of dynamic forms.


Ok, this is what I've tried;

first;
I've put the code in the template, results;

with PHP tags in the mailtemplate :

After submitting, I've got this;

Fatal error: Class 'JRequest' not found in /****/****/****/****.**/www/components/com_chronocontact/chronocontact.php(307) : eval()'d code on line 56

without tags in the mailtemplate:

I received this in my mail;

$result_array = array(); $field_array = array( 'Aanhef', 'Naam', 'Geboortedatum', 'Nationaliteit' ); // get the results foreach ( $field_array as $field) { $result_array[$field] = JRequest::getVar($field, '', 'post'); } // get the number of results $count = count($results_array['Aanhef']); // output the results for ( $i = 1; $i <= $count; $i++ ) { // only out put if Naam has a value if ( $field_array['Naam'][$i] ) { // output a result block echo "
"; foreach ( $field_array as $field ) { echo $field[$i]."
"; } echo "
"; } }
Red colored: changes I've add on in the script because I think you forgot to put it, (I think🙄 )

second;

I'm still using Joomla 1.0.15. So I've got an older version of CF. When I have to turn off the Template Editor is this located here:

General--> Select the format to use for the email.:-->[fieldtitles] or [use emailtemplate]?

When I turned this of I received the next mail;
----
submit Aanvraag versturen(send mail)
Aanhef 1, 2
Naam 1, 2
Geboortedatum 1, 2
Nationaliteit 1, 2
-----
(instead of names I've used numbers to fill up the form.)

If I don't use the mailtemplate, then I will not be able to configure my mail. It's all very complicated, but I hope that it can be solved stp by step.

Greetings,

Frank
GreyHead 21 Mar, 2009
Hifranky2nl,

Sorry, I hadn't realised you were using Joomla 1.0 still - that was Joomla 1.5 code.

The template editor doesn't exist in Joomla 1.0 either so you can forget that bit.

Try changing this line
$result_array[$field] = JRequest::getVar($field, '', 'post);
to
$result_array[$field] = $_POST[$field];


You *must* include the <?php and ?> tags in the email template; you *must* have use Email template set to yes.

Bob
franky2nl 21 Mar, 2009
Hi Bob,

Yep, still using the old one. Till june it's supported after that no more (by the way there haven't been an update for months) In the summer I want to upgrade. But I'm waiting what will happen; because they are building a new version next to the 1.5 (1.6 or maybe 2.0). At this moment there is no releasing date. It can also be in this way that it takes several months when it will be released. So I wait a little bit longer. Maybe I will skip 1.5 and wait for the upgrade.

Ok, back to the problem;

It is sending the mail and I receive it. But nothing is shown.

But little by little I'm getting what this script should dolightbulb . It collects all inputs which has been filled up in the form and you POST all this FIELD. I'm getting somewhere in the world of PHP :wink: .

greetings,

Frank
GreyHead 21 Mar, 2009
Hi franky2nl,

Please turn DeBug On in the General Tab and show me what the results are when you submit the form.

Bob
franky2nl 21 Mar, 2009
Hi Bob,

DeBug is on, with this results;

This is shown on my website after Submit;

------
_POST: Array ( [Aanhef] => Array ( [0] => 1 [1] => 2 ) [Naam] => Array ( [0] => 1 [1] => 2 ) [Geboortedatum] => Array ( [0] => 1 [1] => 2 ) [Nationaliteit] => Array ( [0] => 1 [1] => 2 ) [submit] => Aanvraag versturen )
Case 2: Use template
E-mail: 'Yes' custom
Email sent
-------

I received a mail, but nothing is shown.

Frank
GreyHead 21 Mar, 2009
Hi franky2nl,

That all looks OK, except that no email is showing :-(

Now please try this in the email template. I fixed an Aanhef that didn't have the capital letter and added some debug code.
<?php
$result_array = array();
$field_array = array( 'aanhef', 'Naam', 'Geboortedatum', Nationaliteit );
echo "field_array: ".print_r($field_array, true)."<br /><br />":
// get the results
foreach ( $field_array as $field) {
  $result_array[$field] = $_POST[$field];
}
echo "result_array: ".print_r($result_array, true)."<br /><br />":
// get the number of results
$count = count($results_array['Aanhef']);
echo "count: ".print_r($count, true)."<br /><br />":
// output the results
for ( $i = 1; $i <= $count; $i++ ) {
  // only out put if Naam has a value
  if ( $field_array['Naam'][$i] ) {
    // output a result block
    echo "<div>";
    foreach ( $field_array as $field ) {
      echo $field[$i]."<br />";
      }
  echo "</div>";
  }
}
?>

Bob
franky2nl 21 Mar, 2009
Hi Bob,

First I received - after sending - an error message which I was able to solve! after the <br />" there was : and it had to be ; I'm starting to get an expert to :wink: .

This is what I received in the mail (I've turned DeBug off):

field_array: Array ( [0] => Aanhef [1] => Naam [2] => Geboortedatum [3] => Nationaliteit )

result_array: Array ( [Aanhef] => Array ( [0] => Frank [1] => Laris ) [Naam] => Array ( [0] => Frank [1] => Laris ) [Geboortedatum] => Array ( [0] => Frank [1] => Laris ) [Nationaliteit] => Array ( [0] => Frank [1] => Laris ) )

count: 0

The code with changes;

<?php
$result_array = array();
$field_array = array( 'Aanhef', 'Naam', 'Geboortedatum', Nationaliteit );
echo "field_array: ".print_r($field_array, true)."<br /><br />";
// get the results
foreach ( $field_array as $field) {
$result_array[$field] = $_POST[$field];
}
echo "result_array: ".print_r($result_array, true)."<br /><br />";
// get the number of results
$count = count($results_array['Aanhef']);
echo "count: ".print_r($count, true)."<br /><br />";
// output the results
for ( $i = 1; $i <= $count; $i++ ) {
// only out put if Naam has a value
if ( $field_array['Naam'][$i] ) {
// output a result block
echo "<div>";
foreach ( $field_array as $field ) {
echo $field[$i]."<br />";
}
echo "</div>";
}
}
?>


Frank
GreyHead 21 Mar, 2009
Hi franky2nl,

I've found a typo. Please replace
$count = count($results_array['Aanhef']);
with
$count = count($result_array['Aanhef']);
and test again.

Bob
franky2nl 22 Mar, 2009
Hi Bob,

I recieve this by email;

----
field_array: Array ( [0] => Aanhef [1] => Naam [2] => Geboortedatum [3] => Nationaliteit )

result_array: Array ( [Aanhef] => Array ( [0] => me [1] => you ) [Naam] => Array ( [0] => me [1] => you ) [Geboortedatum] => Array ( [0] => me [1] => you ) [Nationaliteit] => Array ( [0] => me [1] => you ) )

count: 2
----

We are getting closer, I receive the information I want! But how can I put it in a nice template (without the tags) so I can send it to ourselves and the customer.

You already earn some medals🤔

greetings,

Frank
GreyHead 22 Mar, 2009
Hi franky2nl,

One more version
<?php
$result_array = array();
$field_array = array( 'Aanhef', 'Naam', 'Geboortedatum', Nationaliteit );
echo "field_array: ".print_r($field_array, true)."<br /><br />";
// get the results
foreach ( $field_array as $field) {
  $result_array[$field] = $_POST[$field];
}
echo "result_array: ".print_r($result_array, true)."<br /><br />";
// get the number of results
$count = count($result_array['Aanhef']);
echo "count: ".print_r($count, true)."<br /><br />";
// output the results
for ( $i = 0; $i < $count; $i++ ) {
  // only out put if Naam has a value
  if ( $result_array['Naam'][$i] ) {
    // output a result block
    echo "<div>";
    foreach ( $field_array as $field ) {
      echo $result_array[$field][$i]."<br />";
    }
    echo "</div>";
  }
}
?>

Bob
franky2nl 22 Mar, 2009
Hi Bob,

I tried the script and it works! Thank you very much!


I have made some changes;

I deleted some echo's and I managed to show the results in a horizontal way in stead of vertical.

Know the mail shows this;

----------
Aantal deelnemers: 2

a a a a
b b b b
-----------

Is it possible to show it in this way;

1. starting with titles
2. showing the numbers first of the passenges. The count has to start with 2 because the main passenger who will make the reservation has to fill up all his information (also mail adress and phonenumber, but this part I can do by myself) before this part of the form has to be filled up.

With this as result;

---------
number: Aanhef: Voor- en achternaam: Geboortedatum: Nationaliteit:
#2 a a a a
#3 b b b b
----------

But if I want to achive this, I have to work with a table. And then the {field} results have to be seperated, I think so. aAd this is a major operation to do, and I don't know if you want to do this. I'm already happy that you came to this stage. I started to make a kind of example and added a table into the script. I'm getting to learn little by little more about PHP. This is the script;

<fieldset><legend>Overige deelnemers</legend>
<?php
$result_array = array();
$field_array = array( 'Aanhef', 'Naam', 'Geboortedatum', 'Nationaliteit' );
// get the results
foreach ( $field_array as $field) {
$result_array[$field] = $_POST[$field];
}
// get the number of results
$count = count($result_array['Aanhef']);
echo "Aantal deelnemers: ".print_r($count, true)."<br /><br />";
echo "<table border='1'>"; 
echo "<tr> <th>number:</th> <th>Aanhef:</th> <th>Voor- en achternaam:</th> <th>Geboortedatum:</th> <th>Nationaliteit:</th> </tr>"; 
echo "<tr><td>";  
echo "#2"; 
echo "</td><td>"; 
echo "a"; 
echo "</td><td>"; 
echo "a"; 
echo "</td><td>";  
echo "a"; 
echo "</td><td>";  
echo "a";
echo "</td></tr>";  
echo "<tr><td>";  
echo "#3"; 
echo "</td><td>"; 
echo "b"; 
echo "</td><td>"; 
echo "b"; 
echo "</td><td>";  
echo "b"; 
echo "</td><td>";  
echo "b";
echo "</td></tr>";
echo '</table>';
// output the results
for ( $i = 0; $i < $count; $i++ ) {
// only out put if Naam has a value
if ( $result_array['Naam'][$i] ) {
// output a result block
echo "<div>";
foreach ( $field_array as $field ) {
echo $result_array[$field][$i]."    ";
}
echo "</div>";
}
}
?>
<br>
</fieldset>


This is a global situation of how the form will be;

1. The total price of the booked trip (including all parts, like insurance extra price for single room, etc..)
2. The name of the main passenger, the one who is making the reservation.
3. The names of the other passengers (the part which you have worked out)
4. Some additional information.

Part 1, 2 and 4 I can do by myself.

But if it's too much work to put the results in a table shown above, then you don't have to do it.

greetings,

Frank
franky2nl 23 Mar, 2009
Hi Bob,

I've looked on the internet and found out that the table I mean to develope is a 'dynamic table'. But then you havo to 'split up' the [field] value into several field options. Now all fields are combined together and shown in one row or called 'div'. So - when I'm right - you have to create several 'div' to? Because the results would be put in seperated cells of the table? As you see I've found out to put a table in PHP (my first PHP code! with help of the internet🙄 ) But how to change the rest of it.....abracadabra😟 . I even don't know if its possible to do. I think yes but it costs a lot of time to do. What is the next option?

greetings,

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