CodeIgniter Forums
How to handle two submit buttons with two destinations ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to handle two submit buttons with two destinations ? (/thread-9242.html)



How to handle two submit buttons with two destinations ? - El Forum - 06-18-2008

[eluser]Dagobert Renouf[/eluser]
Hello everyone.

I have a form that displays all my articles with a checkbox next to each one, so the user can select a bunch of them to edit or delete them.
The fact is a form can only have one action destination, so if I set the delete destination => edit won't load, and If i set the edit action => delete won't load.

So what I'm asking is : how can I handle this right ?


How to handle two submit buttons with two destinations ? - El Forum - 06-18-2008

[eluser]wiredesignz[/eluser]
Its all edit action, make delete a function of edit.


How to handle two submit buttons with two destinations ? - El Forum - 06-18-2008

[eluser]Dagobert Renouf[/eluser]
thanks a lot wiredesignz that's so simple.
Now I handled the delete action on the edit function, but I'm still trying to handle the edit function by itself !

I'm totally messed up with the idea of displaying all fields of editable articles at the same time and in the same form.
How would some php guru do (I just need the logic) to display a certain amount of "edit" form withs - for each specific form - the data's already field in ?


How to handle two submit buttons with two destinations ? - El Forum - 06-18-2008

[eluser]louis w[/eluser]
Use one destination but name them differently.

Code:
<input type="submit" name="do_edit" value="EDIT" />
<input type="submit" name="do_delete" value="DELETE" />

The value for the button will only get submitted for the one you click on.
Then in your controller test against it:

Code:
if ($this->input->post('do_delete') == 'DELETE') {
    // DELETE
} if ($this->input->post('do_edit') == 'EDIT' {
    // EDIT
} else {
    // WHOOPS
}



How to handle two submit buttons with two destinations ? - El Forum - 06-18-2008

[eluser]Dagobert Renouf[/eluser]
thanks a lot louis w.
Sadly, I already handled that :-D. But your answer confirm the way I did, that's the exact same code ;-).

Now I'm seeking help to handle validation on multiple fields at the same time, would you have any thought ? I'm hoping for a guru to help me out, that's tough.