This is the continuation of my previous issue. I made the code simple and suspecting issue is with second form submission.
This is the code structure:
- A form
(form1) with two input field for name and place - After form submission,(and ONLY if in two fields, user entered data) creating an another form
(form2)with atext areato display thephp echofrom previous form and another two submit buttons - In actual I am using the second form's submit buttons for text save and email (here I just replaced it with a simple textarea echo to make it simple)
CODE:
<html>
<body>
<div class="emcsaninfo-symcli-main">
<form id="form1" name="form1" action=" " method="post" >
<div class="input">Your Name</div>
<div class="response"><span><input class="textbox" id="myname" name="myname" type="text" value="" /></span> </div>
<div class="input">Your Place</div>
<div class="response"><span><input class="textbox" id="myplace" name="myplace" type="text" value="" /></span> </div>
<div class="submit">
<input id="first_submit" type="submit" name="first_submit" value="first_submit" />
</div>
</form>
<?php
if(!empty($_POST['myname']) && !empty($_POST['myplace']) )
{
$myname = $_POST['myname'];
$myplace = $_POST['myplace'];
?>
<form id="form2" name="form2" action=" " method="post" >
<textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly>
<?php
echo "My name is $myname and I am from $myplace";
?>
</textarea>
<input id="submit1" type="submit" name="name_field" value="submit1" />
<input id="submit2" type="submit" name="place_field" value="submit2" />
</form>
<?php
function name()
{
echo $_POST["output_textarea"];
}
if(isset($_POST['name_field']))
{
name();
}
function place()
{
echo $_POST["output_textarea"];
}
if(isset($_POST['place_field']))
{
place();
}
}
?>
</div>
</html>
</body>
Issue:
The first form form1 submit works fine.It will create the output textarea with two other submit button submit1 and submit2. But when I submitting the second form form2 using these two buttons, the form is not submitting properly, it just refreshing the html with initial code.
My requirement is when I press the second form submit button, it has to echo the output from textarea again, after keeping the first form textarea in its position.
PHP FIDDLE:
I have setup a php fiddle to understand the issue PHP FIDDLE MAIN PHP FIDDLE execution results -