get value of submit in Text field when form is post in PHP
I need the value of submit but开发者_StackOverflowton when form is posted in existing text field. and below is the code.
I trying out but it is creating a new text field.
<?php
$var1 = $_POST['hello'];
//below here i am trying out something but not getting in exiting textfield.
//i need the value of submit button ie some value in exiting textfield ie text1
echo "<input type='text' name='text1' value='$var1'>";
?>
<form method="post">
<input type="submit" name="hello" value="some value">
<input type="text" name="text1" value="dskfjls">
</form>
It would create a new text field, because that's what you're echo
is doing.
Just change it do:
<?php
$submitbutton = $_POST['hello'];
$textbox = $_POST['text1'];
//below here i am trying out something but not getting in exiting textfield.
//i need the value of submit button ie some value in exiting textfield ie text1
echo $submitbutton;
echo $textbox;
?>
<form method="post">
<input type="submit" name="hello" value="some value">
<input type="text" name="text1" value="dskfjls">
</form>
Edit in reply to comment
Use this:
<form method="post">
<input type="submit" name="hello" value="some value">
<input type="text" name="text1" value="<?php (isset($_POST['hello'])?$_POST['hello']:null); ?>">
</form>
精彩评论