Keep form data inside the field after submission using php -
i using below code html form.(it has 2 forms) able keep textarea field after first , second form submission. issue facing here dropdown menu selection.
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="<?php if(isset($_post['myname'])) { echo htmlentities ($_post['myname']); }?>" /></span> </div> <div class="input">your place</div> <div class="response"><span><input class="textbox" id="myplace" name="myplace" type="text" value="<?php if(isset($_post['myplace'])) { echo htmlentities ($_post['myplace']); }?>" /></span> </div> <div class="input-quest">graduation status</div> <div class="input-resp"><select id="graduation" name="graduation" onchange="cmt();"><option class="dropdown-options">graduate</option><option class="dropdown-options">non graduate</option></select></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']) || !empty($_post['output_textarea'] ) ) { $myname = $_post['myname']; $myplace = $_post['myplace']; $graduation = $_post['graduation']; ?> <form id="form2" name="form2" action=" " method="post" > <textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly value="<?php if(isset($_post['output_textarea'])) { echo htmlentities ($_post['output_textarea']); }?>"> <?php echo "my name $myname , $myplace, , $graduation"; ?> </textarea> <input id="submit1" type="submit" name="name_field" value="submit1" /> <input id="submit2" type="submit" name="place_field" value="submit2" /> <input id="myname_hidden" name="myname" type="hidden" value="<?php if(isset($_post['myname'])) { echo htmlentities ($_post['myname']); }?>"/> <input id="myplace_hidden" name="myplace" type="hidden" value="<?php if(isset($_post['myplace'])) { echo htmlentities ($_post['myplace']); }?>" /> <input id="graduation_hidden" name="graduation" type="hidden" value="<?php if(isset($_post['graduation'])) { $graduation = $_post['graduation']; }?>" /> </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>
for example if put name = john
, place : uk
, selecting graduation status graduate
, will give me first form output in output textarea
my name john , uk, , graduate
i have 2 seperate submit button second form, using doing other function of output textarea
if press of second button,i m able keep entries name , place area, not keeping dropdown selection. display after submitting submit1
or submit2
my name john , uk, ,
here,
- how can keep the dropdown selection output text area
- will able show output_textarea content after second form submission without keeping first form data ?
you have error in logic in hidden input "graduate" element.
have @ lines 53-55. line 55 doesn't have echo instead has $graduation = $_post['graduation'];
won't you:
<input id="myname_hidden" name="myname" type="hidden" value="<?php if(isset($_post['myname'])) { echo htmlentities ($_post['myname']); }?>"/> <input id="myplace_hidden" name="myplace" type="hidden" value="<?php if(isset($_post['myplace'])) { echo htmlentities ($_post['myplace']); }?>" /> <input id="graduation_hidden" name="graduation" type="hidden" value="<?php if(isset($_post['graduation'])) { $graduation = $_post['graduation']; }?>" />
instead of that, code should work:
<input id="myname_hidden" name="myname" type="hidden" value="<?php if(isset($_post['myname'])) { echo htmlentities ($_post['myname']); }?>"/> <input id="myplace_hidden" name="myplace" type="hidden" value="<?php if(isset($_post['myplace'])) { echo htmlentities ($_post['myplace']); }?>" /> <input id="graduation_hidden" name="graduation" type="hidden" value="<?php if(isset($_post['graduation'])) { echo htmlentities($_post['graduation']); }?>" />
Comments
Post a Comment