[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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
5
Medium Priority
?
158 Views
Last Modified: 2012-05-06
Problem:
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
}
</script>
 
<div id="inner">
<input type="checkbox" name="one" />
<input type="checkbox" name="two" />
<input type="checkbox" name="three" /><br />
<textarea></textarea>
<input type="button" onclick="formsub();" value="Submit" />
</div><br />
<br />
 
<div id="inner2" style="border:1px solid #000000;">
 
</div>

Open in new window

0
Comment
Question by:tech1984
  • 3
  • 2
5 Comments
 
LVL 111

Expert Comment

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

Author Comment

by:tech1984
ID: 24168433
Yup
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24168516
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.
0
 

Author Closing Comment

by:tech1984
ID: 31571471
You are right, there is no easier way then to do what I am already, it is possible but to labor intensive!. Thanks
0
 
LVL 111

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 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