Forums

Certain fields in email, skip others

bobmijwaard 02 Oct, 2010
I have created a form for ordering pizza's.
An pizza can be ordered by choosing an value form a dropdownbox. The form contains about 60 items.
The result will be send by email to the shop, but I only will send a list with the ordered items, the <0> items can be skipped.

Can this be done with chronoforms.

Example output form:

2 ordered pizza 1
3 ordered pizza 2
0 ordered pizza 3
2 ordered pizza 4

The email result should be:
2 ordered pizza 1
3 ordered pizza 2
2 ordered pizza 4
Max_admin 03 Oct, 2010
Hi,

So you only have 1 dropdown box for that in your form ? Can you show us how your form code looks like or even a sample ? and your email template code as well.

Cheers,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
bobmijwaard 03 Oct, 2010
Here is a link to the provisional form:
http://www.pizzapazzo.nl/index.php?option=com_chronocontact&chronoformname=bestellijst

As you can see there are (for this moment)three options you can choose from. Only the items choosen > 0 should appear in the email send to the pizza shop.

Email template so far:
Adresgegevens:
{naam}
{adres}
{postcode} {plaats},
{telefoon}
{email}

Bezorg/afhaalgegevens
Datum: {datum}
Tijdstip: {tijdstip}
Vervoer: {afhalen}

Opmerkingen:
{opmerking}

Bestelling:
{A1}
{A2}


I have placed very simple PHP-code in the "on submit box" before sending the email:
<?php
$B1 = 10000
?>
and try to retrieve the variable B1 in the email, without succes. It seems that code from this boxcan not be used in the email.
GreyHead 03 Oct, 2010
Hi bobmijwaard ,

Given that this is likely to be a long list I'd take a slightly different approach and use PHP to manage the data from the start. Here's an example where I've put the data into an array - in practice I'd use a database table and some extra forms to manage the table.

The Form HTML is
<?php
if ( !$mainframe->isSite() ) { return; }
$product_array = array();
$product_array['1']['id'] = "A1";
$product_array['1']['naam'] = "Italiaans brood met kruidenboter";
$product_array['1']['prijs'] = 3.00;
$product_array['1']['beschrijving'] = "";
$product_array['2']['id'] = "A2";
$product_array['2']['naam'] = "Cocktail al gamberetti";
$product_array['2']['prijs'] = 7.00;
$product_array['2']['beschrijving'] = "Garnalencocktail van noorse garnalen met whiskysaus";
$product_array['3']['id'] = "A3";
$product_array['3']['naam'] = "Carpaccio di salmone ";
$product_array['3']['prijs'] = 8.00;
$product_array['3']['beschrijving'] = "Plakjes gerookte zalm met Parmezaanse kaas, ui grof gemalen peper en rucola";

$options = "";
$options .= "<option value=''>0</option>"; 
foreach (range(1, 10) as $n ) {
  $options .= "<option value='$n'>$n</option>";
}

echo "<table>";
foreach ( $product_array as $k => $p ) {
  echo "<tr>";
  echo "<td><select name='q[".$p['id']."]' id ='q_".$p['id']."'>
  $options
  </select></td>";
  echo "<td>".$p['id']."</td>";
  echo "<td><strong>".$p['naam']."</strong><br />".$p['beschrijving']."</td>";
  echo "<td>€ ".$p['prijs']."</td>";
  echo "</tr>";
}
echo "</table>";
?>
<input type='submit' name='submit' />

NB I've left out the address fields here and I haven't bothered with the formatting. This generates a form very similar to yours. But all the quantity data is returned in a single data array like q = array( A1 => 0, A2 => 4, . . .

Important: to stop ChronoForms messing with the array you must set "ChronoForms handle my posted arrays:" to 'No'

The corresponding OnSubmit Before code is
<?php
// include the same product_array here !!

$q = JRequest::getVar('q', array(), 'post', 'array');
$output = array();
foreach ( $product_array as $p ) {
  if ( $q[$p['id']] ) {
    $output[] = $q[$p['id']]. ' : '.$p['naam'];
  }
}
$output = implode('<br />', $output);
JRequest::setVar('output', $output);
?>
You can then add {output} into the Email template and the result is like:

5 : Italiaans brood met kruidenboter
3 : Carpaccio di salmone



Bob
bobmijwaard 03 Oct, 2010
Bob,

Thanks a lot !!!!.
Again I am amazed about the extensive answer you gave. It's working like a charm, I only have to add some css code.
bobmijwaard 24 Oct, 2010
Based on the above post I need to have the total prize of the order. I tried several things but didn't find the solution due to my poor PHP skills.

So the idea is displaying one value for the total order (in the email)
GreyHead 24 Oct, 2010
Hi bobmijwaard,

You can keep a running total in the OnSubmit Before box
<?php
// include the same product_array here !!

$q = JRequest::getVar('q', array(), 'post', 'array');
$output = array();
$total = 0; // <- add this line
foreach ( $product_array as $p ) {
  if ( $q[$p['id']] ) {
    $output[] = $q[$p['id']]. ' : '.$p['naam'];
    $total += $q[$p['id']] * $p['prijs']; // <- add this line
  }
}
$output = implode('<br />', $output);
JRequest::setVar('output', $output);
JRequest::setVar('total', $total); // <- add this line
?>
You may need to add some formatting to make it look pretty.

Bob
bobmijwaard 24 Oct, 2010
Thnaks again Bob.
In fact I was quite close with my solution:
$total = $q[$p['id']] * $p['prijs']; //

instead of yours
$total += $q[$p['id']] * $p['prijs']; //


Why is += used here??

Note: I already got it += means that the second value is added to the first and so on.
This topic is locked and no more replies can be posted.