Does anyone know how to make inputs in a textbox
and selectbox
remain after page refreshed?
I want to make my inputs remain afer page refreshed if the user unable to fill all the required filleds in a registration page.
Does anyone know how to make inputs in a textbox
and selectbox
remain after page refreshed?
I want to make my inputs remain afer page refreshed if the user unable to fill all the required filleds in a registration page.
you should validate your form before sending it to server, in client side with javascript
set the value of the field to the posted value eg:
<form method="POST">
<input name="username" value="<?php echo $_POST['username']; ?>"/>
<input type="submit"/>
</form>
I assume you meant 'form submit' by 'page refresh'. Here how you do it.
For text fields:
<input type="text" name="text_field" value="<?php echo @$_POST['text_field']"; ?>/>
For select fields:
<select name="select_field">
<option value="1" <?php echo @$_POST['select_field'] == "1" ? "selected" : '' ?>>an Option</option>
<option value="2" <?php echo @$_POST['select_field'] == "2" ? "selected" : '' ?>>another Option</option>
</select>
NOTE: @
symbols is to suppress the error when you load the page for the first time.
Hope this helps :)