0

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.

<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>
5
Contributors
6
Replies
12
Views
5 Years
Discussion Span
Last Post by pritaeas
0

You are not loosing anything actually, at a time you can handle only one form request.

If you submit form1 then only email and mail-submitting will be sent to action page
If you submit form2 then only email,subject and contact-submitting will be sent to action page

0

Is there a way around it? what i am trying to do is a bigger task actually, the first form is submitted from .html,

the second form is submitted from .php file where the variables from the .html gets null.

i can provide the actual code of the actual program that i am writing. i am writing this as a practice but if it works in a way how i want it to work it will help 25 employees to do their calculations faster (and get them lazier :)

0

you can send on all the post vars again

foreach($_POST as $k=>$v){
$allowedchars = array('@','-','.','_');
$tk = str_replace($allowedchars,'',$k);
$tv = str_replace($allowedchars,'',$v);
if(ctype_alnum($tk) && ctype_alnum($tv)){
echo "<input type='hidden' name='{$k}' value='{$v}'/>\r\n";
}
}

add to the allowed chars if you want to let more chars through, or just validate it some other way - it just can't contain quotes really. also watch for ones with the same name

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.