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

Posted on 2009-04-17
Last Modified: 2012-05-06
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

Question by:tech1984
    LVL 107

    Expert Comment

    by:Ray Paseur
    "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?

    Author Comment

    LVL 107

    Accepted Solution

    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.

    Author Closing Comment

    You are right, there is no easier way then to do what I am already, it is possible but to labor intensive!. Thanks
    LVL 107

    Expert Comment

    by:Ray Paseur
    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.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now