AJAX and php copy a form after it has been filled out then pass populated html to php to mail out

Client wants to email a form that has been populated by a user. The form needs to keep its structor and be sent to the client like it is

My Original Solution:
Take all of the $_POST data and recreate the form on a "thank_you.php" page. Then take that data and email it out. This solutions works, however, the forms have 75 to 80 fields! And I am getting tired of $_POST['form_field']; in every freaking input, and the if statements on the checkboxes, well you know where I am going here. Basically my solution does work, but there has got to be a faster way.

My idea:
What I would like to do is create some AJAX that passes the innerHTML of a form to a PHP page, and then just email the variable that contains all the data. My first problem was that I could get the innerHTML of a div item (which contains the form), but of course it doesn't retain any server side changes, like checked check boxes, filled in input boxes and such. I mad a simple moc up of what I am trying to do attached. Basically, if I can get the attached code to pass the checked items and such, I can make the AJAX issue work. HELP!!!
<script type="text/javascript">
function formsub()
filled_form = document.getElementById("inner").innerHTML
document.getElementById("inner2").innerHTML = filled_form
<div id="inner">
<input type="checkbox" name="one" />
<input type="checkbox" name="two" />
<input type="checkbox" name="three" /><br />
<input type="button" onclick="formsub();" value="Submit" />
</div><br />
<br />
<div id="inner2" style="border:1px solid #000000;">

Open in new window

Who is Participating?
Ray PaseurConnect With a Mentor Commented:
Hmm.  I think I like your first answer best.  I think I might want to take the client input from $_POST, store it in a data base table and send a link to the end-user of the email.  The link would take the end-user to a www page that would put up a form with the fields populated from the data base table.  If you want to allow the end user to modify some of the fields in the form you could do that, or you could just mark the fields READONLY.

The issue with checkboxes is that unchecked boxes are not present in $_POST so you need some independent knowledge of them in order to replicate the form.  IIRC, radio buttons are the same way.  So just sending $_POST information is not enough - you need to know what else was on the form and not filled in.  That is where the DB table would be useful.
Ray PaseurCommented:
"The form needs to keep its structor and be sent to the client like it is"

Does this mean you need to reproduce the input web page for the client to see in the email?
tech1984Author Commented:
tech1984Author Commented:
You are right, there is no easier way then to do what I am already, it is possible but to labor intensive!. Thanks
Ray PaseurCommented:
Thanks for the points.  I've always thought that this "missing checkbox" thing was one of the design flaws of the www.  If only they all came through in $_POST with a zero or a one.. Sigh.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.