Advanced form with calculation

tintin_dk 06 Jan, 2013
Hi folks!

I have been trying for a long time now to find out how to make a form as you can see here:
https://www.dropbox.com/s/93egfvqeq4rnqim/fsk_km2013.pdf

The form needs to calculate how many of 1: and 2: and the user must be allowed to input a time beneath DBU-tid. At the end it must calculate a total.

Is it possible at all?

Thanks a lot :-) !

Michael
GreyHead 07 Jan, 2013
Hi Michael,

This is certainly possible. How far have you got and exactly what problems are you having?

Bob
tintin_dk 07 Jan, 2013
Hi, Bob!

Thanks a lot for your prompt reply :-) !

Actually not that far :-/

I have been trying to get multiple fields in one line and to find out how to make the calcultations in the form?

Hope you can help ;-)!

Thanks,
Michael
GreyHead 07 Jan, 2013
Hi Michael,

I'd probably create the rows using PHP in a Custom Code element, and I'd store the data needed to do them in an array to make it easy to edit. Something like this for the Ladies part:
<?php
$dame_data = array();
$dame_data[] = array(
  'hold' => 'U7 piger', 
  'argang' => '06',
  'spillere' => '3+2',
  'pris' => '200'
);
$dame_data[] = array(
  'hold' => 'U8 piger', 
  'argang' => '05',
  'spillere' => '3+2',
  'pris' => '200'
);
$dame_data[] = array(
  'hold' => 'U9 piger', 
  'argang' => '04',
  'spillere' => '4+3',
  'pris' => '250'
);
// and so on
$dame_data[] = array(
  'hold' => 'Dame senior', 
  'argang' => 'fyldt',
  'spillere' => '4+2',
  'pris' => '370'
);
?>
<table>
  <thead>
    <tr>
      <th>Hold</th>
      <th>Argang</th>
      <th>Spillere</th>
      <th colspan = '2'>Antal hold i niveau</th>
      <th>DBU-tid</th>
      <th>Pris</th>
    </tr>
  </thead>
  <tbody>
<?php
foreach ( $dame_data as $k => $d ) {
  echo "
    <tr>
     <td>{$d['hold']}</td>
     <td>{$d['argang']}</td>
     <td>{$d['spillere']}</td>
     <td><input type='text' class='' name='antal[$k]' id='antal_{$k}' value='' /></td>
     <td><input type='text' class='' name='niveau[$k]' id='niveau_{$k}' value='' /></td>
     <td><input type='text' class='cf_time_picker' name='tid[$k]' id='tid_{$k}' value='' /></td>
     <td>{$d['pris']}</td>
    </td>
";
}
?>
  </tbody>
</table>

This is not very pretty but should get you started.

Once you have the form working you can use JavaScript to add up the totals to display them in the form, and/or PHP to add them after the form is submitted.

Bob
tintin_dk 07 Jan, 2013
Hi again,

Thanks a lot Bob - you're the best :-) !

I will work on it and see if I can figure it out :-)!

Thanks again!

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