Welcome Guest, Not a member yet? Register   Sign In
How to reset 'set_value' after valid form post
#1

[eluser]Hein[/eluser]
Hi all,

I've tried searching for an answer on this one, but to no avail. Hope you can help.

I have a form that repopulates itself with 'set_value' when errors were detected via 'form_validation'.

This works fine. But when the post was successful, I want to reshow the same form. Only now I want all the fields to stay blank.

Is there a way of 'resetting' the 'set_value' values?

Code:
<?= form_open('', array('name'=>'reaction', 'id'=>'reaction-form')); ?>
    <input type="text" name="name" id="name-field" value="<?= set_value('name', '') ?>" />
    <textarea cols="" rows="" name="reaction" id="reaction-field"><?= set_value('reaction', ''); ?></textarea>
    <button type="submit" value="ok" >Verstuur</button>
&lt;/form&gt;
#2

[eluser]pistolPete[/eluser]
You could redirect() to the same page in order to empty the $_POST data:
http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]Hein[/eluser]
Thanks PistolPete Smile

To be honest, this one the options I thought about. But decided not to go that route since I thought it would be considered somewhat of a 'hack':

-> form post -> controller (form check) -> redirect to same controller

My feeling tells me that I should be trying to find a way to handle it all in one controller call. I'm interested to hear your opinion on this.
#4

[eluser]Colin Williams[/eluser]
Redirecting after successful form posts is generally a good idea, and a good, common practice. For one, it prevents double-posting. Nothing hacky about it1
#5

[eluser]Hein[/eluser]
@Colin: thanks! Then that's the way to go.




Theme © iAndrew 2016 - Forum software by © MyBB