0

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.

http://www.tinsgroup.com/forms_and_applications/FBO%20Insurance%20Application_12-13-10.pdf

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 />";
            }
2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by diafol
0

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.

0

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

0

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.

0

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

0

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:

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

<script type="text/javascript">
$('#change').click(function(event){
    event.preventDefault();
    $('input').each(function(){
        $(this).parent().html($(this).val());   
    });
    alert($('#mytable').html()); //just show what's changed
});

</script>
</body>
</html>

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.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.