0

Apologies for re posting but in one of my edits I had forgotten to hide a password so I wasn't wanting someone to be able to go through my edits and find it

Basically I've created an application form and in it there is a table for the user to put in their education details (school they went to, exam results etc). I've created it so the user can add as many rows as necessary but when I try to get what they've put in into an email, it just comes out blank. There is no error so I just can't figure out where I've gone wrong, I'm thinking it might be something small but for the life of me can't see what the error is. Any help would be greatly appreciated

Edit:

I have now done a much simpler way to create the table and now I get values from the table in the email but, the values are just from the last row rather than each one. Really close to getting this right, any pointers would be really appreciated

This is the updated html code for the table:

  <table class="qualifications" id="qualifications" >
  <tr>
  <td><b>Date From</b></td>
  <td><b>Date To</b></td>
  <td><b>Name of School/College/Institute or Professional Body</b></td>
  <td><b>Examinations Taken and Results</b></td>
  </tr>
  <tr>
  <td><input type="text" name="date_from" id="date_from" /></td>
  <td><input type="text" name="date_to" id="date_to"/></td>
  <td><input type="text" name="name" id="school_name" /></td>
  <td><input type="text" name="results" id="results"/></td>
  </tr>
</table>
<a href="#" title="" class="add-row">Add Row</a>

I now use jQuery for letting the user add rows to the table:

  var counter = 1;
jQuery('a.add-row').click(function(event){
    event.preventDefault();
    counter++;
    var newRow = jQuery('<tr><td><input type="text" name="date_from" id="date_from'+
        counter + '"/></td><td><input type="text" name="date_to" id="date_to'+
        counter + '"/></td><td><input type="text" name="school_name" id="school_name' +
        counter + '"/></td><td><input type="text" name="results" id="results' +
        counter + '"/></td></tr>');
    jQuery('table.qualifications').append(newRow);
});

Once the user has completed the form and hit submit application.php runs and the email body for getting the table values I have done:

Date From: {$_POST['date_from']}
Date To: {$_POST['date_to']}
Name: {$_POST['school_name']}
Results: {$_POST['results']}

Like I said this will send values but only from the last row, what can I do so it send the values from every row of the table?

Thanks in advance for any advice

l15
  • 65
  • 1
  • 7
  • If you have multiple inputs with the same name, each of those should be a collection of values. Not sure how iterate that in php (not a php dev). You could add your counter value to the name as well, and then pass with the form how many rows there are (hidden input), then in php get the number of rows and do a for loop and then request the values 1 by 1 in the loop. – NickAndrews Mar 14 '19 at 15:59
  • 1
    Possible duplicate of [Posting array from form](https://stackoverflow.com/questions/6152436/posting-array-from-form) – miken32 Mar 14 '19 at 16:02
  • would you be able to give me an example of that? – l15 Mar 14 '19 at 16:02
  • Just add `[]` to the end of the element name; all values will get sent and PHP will interpret it as an array. – miken32 Mar 14 '19 at 16:03
  • knew it was something obvious I was missing thank you much, had to then do if( isset($_POST['date_from']) && is_array($_POST['date_from']) ) { $from = implode(', ', $_POST['date_from']); } and for the mail body Date From: {$from} – l15 Mar 14 '19 at 16:17

0 Answers0