Forums

Master/Detail form

pthoff 18 Apr, 2013
Hi
I am struggelig with one form I try to create.
Tryed to solve this with multi page form.

Page1: Fill inn the name and Event
Page2: If name and event is not in the database, the user have to fill in birth year+mail+gender
Page3: Has a list from the database in the top, and the user can fill inn more rows, and the user chould also delete rows....
When user press "Save Row" the form submitt, and goes back to page3, so the user can put in a new row. When user is finish the user press "Finiched" button and an epost is sendt.

I struggle with the delete
and the end/finish to go to send epost.

Here is the JS code:
window.addEvent('domready', function() {
  // add code that needs the dom loaded inside this function

  $('Finish').addEvent('click', function(){
    alert('OK!');
  });


  $('Delete').addEvent('click', function(){
    <?php
      $db =& JFactory::getDBO();
      $query = "delete from `Stevne_Registrering` where `input_stevne` = '$detail[input_stevne]' and `input_navn` = '$detail[input_navn]' and `input_svomme_nr` = '$detail[input_svomme_nr]';";
      $db->setQuery($query);
      $data = $db->query();
      ?>
  });
});



and here is the php for the table in the top of page3:
<table width="100%" border="1" cellpadding="1" cellspacing="1">
   <tr>
      <th width="15%" scope="col">Øvelse Nr</th>
      <th width="40%" scope="col">Øvelse</th>
      <th width="20%" scope="col">PåmeldingsTid</th>
      <th width="20%" scope="col"></th>
   </tr>
<?php
foreach($form->data['StevneReg4'] as $detail):
?>
<tr>
<td><?php echo $detail['input_svomme_nr']; ?></td>
<td><?php echo $detail['input_svomme_art']; ?></td>
<td><?php echo $detail['input_svomme_tid']; ?></td>
<td><input type="button" value="Delete" id="Delete"></td>
</tr>
<?php
endforeach;
?>
</table>


Please help.
GreyHead 19 Apr, 2013
Hi pthoff,

I'm afraid that you can't add the PHP & MySQL to delete a record in the middle of your JavaScript and expect it to work. The PHP part will be run when the page is loaded so at best will do nothing and at worst will delete a record from your table. Check the resulting script in you form page to see what is actually created.

You may want to use Ajax for this which requires clicking the delete button to call the URL of a separate form action on the server where you have the PHP+MySQL to actually do the deletion.

Or, alternatively, you may want to have the delete buttons act like submit buttons so that the results are sent to the server for processing and then the form re-loads again with the updated set of data.

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