form not clearing data fields

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
om.bitsian
Forum Commoner
Posts: 36
Joined: Wed Sep 09, 2009 4:13 am

form not clearing data fields

Post by om.bitsian »

Hello friends
i am working on php page. There are around 20 fields like....

<label>4. First Name</label>
<input type="text" name="fnam" size="10" value="<?php if (isset($_POST['submit'])) echo $_POST['fnam'];?>"><br><br>


<label>5. Basic Pay</label>
<input type="text" name="basic" value="<?php if (isset($_POST['submit'])) echo $_POST['basic'];?>">
</select> <br> <br>


when i click on submit button the data are inserting in the data base but after that also value remain in the textbox....the value should clear out whenever i click on submit or when i refresh......but its not happning.....please help me to solve this problem

thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: form not clearing data fields

Post by jackpf »

Remove the code inside the value="..." attribute.
om.bitsian
Forum Commoner
Posts: 36
Joined: Wed Sep 09, 2009 4:13 am

Re: form not clearing data fields

Post by om.bitsian »

i have around 20 entries in my form... when i will remove it and suppose there is a validation in some 15th field.......all the fields will be clear and again i have to enter all the values......do you have any alternate solution for it????????

thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: form not clearing data fields

Post by jackpf »

Look at your code - if the form has been submitted, it will always display the posted data, despite an error, or success.

You could process the form before displaying it (if the form has been submitted), and then set a variable to true on success, or false on failure. Then, also check that the variable is false before displaying the posted data in the form.
Post Reply