• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Sending a form and inserting into a database simultaneously

My user fills in a form and clicks, "Submit." The form is headed to icontact where the user's email is inserted into the database, which is great, but I need to grab that email and insert it into my database as well and I'm trying to figure out a way where I can do that without having to ask the user to enter their email address twice. Is there a way I can do that?
0
brucegust
Asked:
brucegust
1 Solution
 
InventoryMarketingCommented:
Hello,

Do you have any control of the submission after the user clicks submit before it is sent off to the other script/form?  if so you could just create a quick sql query to insert it into your database at that time then send it off to the other script.

Hope this helps
0
 
Mohamed AbowardaSoftware EngineerCommented:
When the user submit the email, store it in sessions variable, you will be able to access it from any page without having to ask the user for the email again.

http://www.tizag.com/phpT/phpsessions.php
http://www.php.net/manual/en/book.session.php
0
 
Greg AlexanderLead DeveloperCommented:
Here is an example
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
function submit_form(){
	$.post("your_php_file.php", { email: ""$("#email").val()""},
  			function(data){
   		});
return true;
}
</script>

<form action="someplace.com" onsubmit="return submit_form()" method="post">
Email <input type="text" name="email" /><br />
<input type="submit" name="submit" value="submit" />
</form>

Open in new window

0
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.

 
Greg AlexanderLead DeveloperCommented:
Actually this one
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
function submit_form(){
        $.post("your_php_file.php", { email: ""$("#email").val()""},
                        function(data){
                });
return true;
}
</script>

<form action="someplace.com" onsubmit="return submit_form()" method="post">
Email <input type="text" name="email" id=email /><br />
<input type="submit" name="submit" value="submit" />
</form>

Open in new window

0
 
Greg AlexanderLead DeveloperCommented:
This will post email to your_php_file.php and you can insert there in the database
0
 
brucegustPHP DeveloperAuthor Commented:
Hey, folks!

Here's the dilemma in what I"m seeing in your suggestions, and it may be that I'm missing something, so we'll see.

The form that I'm using is coming from a third party (icontact.com), so I don't have any control over the data in terms of how it's being sent. All I've got is a field and submit button with the form action being on a server other than my own. The code is attached.

What I've been doing up to this point is that when they submit their info, they're redirected to a page on my server where I have them re-enter their email as way to "validate" their info, when in fact, I'm capturing their email address on my server for the first time.

I want to eliminate that step. I want them to be able to enter their email address one time and be able to post it to icontact AND insert into my database simultaneously.

How?
<form method=post action="https://app.icontact.com/icp/signup.php" name="icpsignup" id="icpsignup3484" accept-charset="UTF-8" onsubmit="return verifyRequired3484();" >
				<input type=hidden name=redirect value="http://www.countryshowdown.com/Texaco/registration_two.php" />
				<input type=hidden name=errorredirect value="http://www.icontact.com/www/signup/error.html" />

					<div id="SignUp">
					<table border="0" cellspacing="0" cellpadding="5">
					<tr>
					 <td valign=top align=right>
					<font size="1" face="Arial,Helvetica, sans-serif">*</font>&nbsp;<font size="2">email</font>
					 </td>
					 <td align=left>
					<input type=text name="fields_email" size="50">
					 </td>
					</tr>
					<tr>
					 <td valign=top align=right>
					<font size="1" face="Arial,Helvetica, sans-serif">*</font>&nbsp;<font size="2">First Name</font>
					 </td>
					 <td align=left>
					<input type=text name="fields_fname" size="50">
					 </td>
					</tr>
					<input type=hidden name="listid" value="43682">
					<input type=hidden name="specialid:43682" value="U0ST">

					<input type=hidden name=clientid value="613341">
					<input type=hidden name=formid value="3484">
					<input type=hidden name=reallistid value="1">
					<input type=hidden name=doubleopt value="0">
					<tr>
					<td colspan="2" align="center"><input type="image" src="images/submit.jpg" border="0" name="submit"></td>
					</tr>
					</table>
					</div>
					</form>
				<script type="text/javascript">

				var icpForm3484 = document.getElementById('icpsignup3484');

				if (document.location.protocol === "https:")

					icpForm3484.action = "https://app.icontact.com/icp/signup.php";
				function verifyRequired3484() {
				  if (icpForm3484["fields_email"].value == "") {
					icpForm3484["fields_email"].focus();
					alert("The Email field is required.");
					return false;
				  }
				  if (icpForm3484["fields_fname"].value == "") {
					icpForm3484["fields_fname"].focus();
					alert("The First Name field is required.");
					return false;
				  }


				return true;
				}
				</script>
				</td>
				</tr>
				<tr>
				<td class="body" align="right"><sup>*</sup><font size="1s"> = required field</font>&nbsp;&nbsp;
				</td>
				</tr>
				</table>

Open in new window

0
 
brucegustPHP DeveloperAuthor Commented:
That will work!
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now