Page 1 of 1

multiple form submits looses data!!! Please Help

Posted: Mon Nov 21, 2011 5:48 pm
by fnyahoo
ok here is my problem, I am kind of new to Php but have done programming before. I am recently learning php so am not sure what php can or cant do.
What i am trying to do here is i have a multiple submit buttons which i input some data and press submit, it works finr but when i enter more data and press another submit button the previous data is lost. What is the solution to that?

The following code is just written as an example.

Code: Select all

<html> 
<head> 
<title>New Tip Calculator</title> 
</head> 
<body> 

<center>



<?php 

echo "<form name='mailinglist' method='post'>
<input type='text' name='email' />
<input type='submit' name='mailing-submit' value='Join Our Mailing List' />
</form>
 
<form name='contactus' method='post'>
<input type='text' name='email' />
<input type='text' name='subject' />
<input type='submit' name='contact-submit' value='Send Email' />
</form>";


if (!empty($_POST['mailing-submit'])) {
$var = $_REQUEST['email'];
	echo"$var";
}
 
if (!empty($_POST['contact-submit'])) {
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];

echo"$email $subject";
echo"$var";

}


?>

</center>

</body>
</html>

Re: multiple form submits looses data!!! Please Help

Posted: Mon Nov 21, 2011 6:43 pm
by Celauran
With the user's email address being the common field between the two forms, you could write it to session data when one form is submitted and have both forms check for said session data when the page loads. There are surely a million other ways to accomplish the same, this is just the first that sprang to mind.

Re: multiple form submits looses data!!! Please Help

Posted: Mon Nov 21, 2011 11:14 pm
by fnyahoo
ok This was an example code, what I am trying to do is a bigger task with more values. But the purpose is almost the same. Can I still use the session as the solution to my problem???

what i am doing is following,

1- (as starting point) i have a seperate html file called tipCalculator.html
it has a form and calls tipCalculator.php page where all the variable from the html being sent.

2- I have tipCalculator.php page which gets the data (by data i mean 6 variables) from the tipCalculator.html
and creates a table and does some calculations and puts them in a table. ALSO in another function, WITHIN the same .php page
I have another form which user inputs 3 more variables and presses the submit button again.

As soon as the user presses the submit button for those 3 more variables in the .php page all the data coming from .html becomes null (or 0). I need that data coming from previous .html page because that data will be used again.

(Please correct me if I am wrong but I think the reason why all the variables coming from the .html becomes null when press submit in .php file is because A Form in .php file calls the same .php file (itself). what i mean is <form action=" " ...> OR <form action="tipCalculator.php") in tipCalculator.php itself.

If it will help I can post the actual code here. That is something that I am writing for my own practice but the program will help about 25 employees to calculate their tip numbers much faster. It has been a good php practice for me, but now i need help. thank you in advance. i can post the actual code let me know.

Re: multiple form submits looses data!!! Please Help

Posted: Tue Nov 22, 2011 6:35 am
by Celauran
fnyahoo wrote:Please correct me if I am wrong but I think the reason why all the variables coming from the .html becomes null when press submit in .php file is because A Form in .php file calls the same .php file (itself). what i mean is <form action=" " ...> OR <form action="tipCalculator.php") in tipCalculator.php itself.
You're wrong. This is quite common practice and works fine. I'd guess it has something to do with how you're populating your second form. Please post the relevant code.