One form, many actions - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: One form, many actions (/showthread.php?tid=2688) |
One form, many actions - El Forum - 08-19-2007 [eluser]Sector[/eluser] Hello, once again I'm stuck on something, and not being able to find a solution that's not hackerish is nagging at me. I have a form, and it contains many checkboxes. (one for each item in a table). At the end of that form, you can press multiple submit buttons. The form is a POST form that points to the controller action with method delegate. I envisioned this method because I cannot let a form point to multiple URLs. What I want to happen is: if a person checks a few checkboxes and presses the 'delete' button, I want to delegate page to reroute to action/delete, with exactly the same POST array. How can I accomplish this with Code Igniter? Thanks very much in advance! One form, many actions - El Forum - 08-19-2007 [eluser]Nillian[/eluser] Hi there, I'm a newbie myself so forgive me if I give you wrong information, but here goes anyway. I assume that your various submit buttons have differing "name" attributes in the HTML? You should be able to put a small piece of code in your 'delegate' function that decides which of these buttons has been pressed and takes the appropriate action (calling the right function from the related Model/Library) An example, in semi-pseudo-code... Code: function delegate() Other than the above code, if you really wanted to do a redirect, that gets a bit more messy I think, what with having to pass the $_POST array on again. You'd probably have to register the contents of $_POST as some kind of global variable to last across pages, and I'm not entirely sure how you do that (yet). I'll browse the forum and see if I can't find a way. That help at all? - Nillian One form, many actions - El Forum - 08-19-2007 [eluser]Sector[/eluser] Thanks Nillian, you gave me an idea that I will try! -> Yes, I had given them different names, so I could branch. Since the pages I wanted to redirect to are in the same file (action controller), I might just as well call the functions: Code: function delegate($id) { I'll see if it works, thanks One form, many actions - El Forum - 08-19-2007 [eluser]Nillian[/eluser] Glad to be of help One form, many actions - El Forum - 08-20-2007 [eluser]alpar[/eluser] yuu could add a simple javascript function thet would ease your job. something like function submit(form,action) { form.action = action; form.submit(); } and the yiu will have something like <input type="button" onclick="submit(this,'delete')" /> and you can add an action to each of thease buttons one for delete and other for other actions, this is more clear than a server side solution, if you have a single buton, you could also add javascript, i am not an exper and i don't guarantee that the above function works as it, i don't have time to tst it... but somehing simmilar will do One form, many actions - El Forum - 08-20-2007 [eluser]Sector[/eluser] That is also a solution which I would consider as viable, because my webpage is completely Ajax-ified. But now I got the server-side solution working wonderfully and very elegantly, so I'll stay with that now: Code: function delegate() { |