I have this rather large form that I need to grab all the user input from and email it. My problem is there are a mixture of normal feilds and then parts of the form are set up in tables. I'm not sure how to go about naming each of the fields in the table so that then I can format the html email so that all that information will be in a table as well. Since not all the fields are in tables I'm not how to go about grabbing all the data and then seperateing it so that in the email all the data that was in a table in the form is in a table in the email and the rest rest of the data can just be printed out. This is how I'm doing it right now. I currently just grabs the posts and then loops through them as key value pairs. And then just prints them out in a line. This fine for the non-table fields, but for things like the pilot roster i would have to name them pilot_1, birth_date_1, cml_1, atp_1, exc. If I print that out with the code I have now it would be rather hard to read. So I was hoping someone could help me with a way to do this.

Here is the link to what the form looks like.


Here's how currently grabbing and setting up the email message.

foreach( $_POST as $name=>$value){
                  $emailMsg .=  "<b>" . htmlspecialchars(var2Readable($name)) . ': ' . "</b>" . htmlspecialchars(clean4Email($value)) . "<br />";

Recommended Answers

All 5 Replies

Member Avatar

You're saving this to DB as well or just firing it off to email and then your server discards all the data?

You could use js to overwrite the form fields with the data held within the form fields and then ajax the whole content to a php file for sending.

Do you know how you would go about doing that? I'm not very experienced with js or ajax.

Member Avatar

You didn't answer the question - what do you do with the data - [send and drop (not save)] or [save and send]? You'd only use the js idea for the first one.

Im just going to be sending the data from the form in an email, I won't be saving it

Member Avatar

Have a look at something like jQuery. You can loop over all inputs that are textboxes and replace the table cell holding the textbox with the value.

here's an example. BTW - I've never done this before, just an idea that hit me:

<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="tablediv">
    <tr><td><input id="lastname" /></td><td><input id="middlename" /></td><td><input id="firstname" /></td></tr>
<button id="change">Change</button>

<script type="text/javascript">
    alert($('#mytable').html()); //just show what's changed


Sorry, that's just proof of concept. You'll need to change the $('input') to meet your needs, ie different actions for textbox, checkbox etc.

After changes are made you can then chose the whole html with:

var ecode = $('#mytable').html();

You can then send this as a string to a php page via Ajax, which then sends the email.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.