开发者

Codeigniter: Submitting Forms

开发者 https://www.devze.com 2022-12-30 22:23 出处:网络
How do I submit a form that开发者_运维技巧 can do two different things based on the URI? For example, if the URI contains a string \"new\" the form will submit differently than it would if \"new\" we

How do I submit a form that开发者_运维技巧 can do two different things based on the URI?

For example, if the URI contains a string "new" the form will submit differently than it would if "new" were not in the URI.

I'm having trouble implementing this, as when a form is submitted, it takes the URI of whatever "form_open" says.


Altering the form_open path is probably not the way to do this. How are you using this? Does the person filling out the form affect the "new" string?

What I would do is put a hidden input on the form and set THAT value to "new". Then in the controller, use a GET to take the value of the input form, and do a simple IF / ELSE statement based off the value of that variable.

This way, you could setup several different ways to use the same form - hidden=new, hidden=old, hidden=brandnew, hiddend=reallyold could all process the form values differently, even sending them to different tables in your DB or whatever.


Kevin - I thought I'd done something like this before and I had - here's a quick look:

In routes.php:

$route['some/pathname/(:any)'] = "my_controller/my_function/$1";

Then in mycontroller.php:

function my_function($type)
{
    if ($type == "new") { 
        do this }
    elseif ($type == "update)" { 
        do this }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号