CodeIgniter Forums
URI change when calling controller functions - 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: URI change when calling controller functions (/thread-41304.html)

Pages: 1 2


URI change when calling controller functions - El Forum - 07-31-2011

[eluser]byde[/eluser]
have you try javascript?

Code:
<form action="controller/handler" method="POST">
<input type="hidden" name="beverage" value="water" />
<input type="submit" name="formAction" o nclic k="this.form.action = 'controller/functionA';" value="a" />
<input type="submit" name="formAction" o nclic k="this.form.action = 'controller/functionB';" value="b" />
</form>



URI change when calling controller functions - El Forum - 07-31-2011

[eluser]Aken[/eluser]
You could use the controller set up as you have shown, and use a method parameter to flag whether or not information should be output, or a redirect to the function page should be used.
Code:
function handler()
{
    if ($action == 'a')
    {
        $this->functionA(true);
    }
}

function functionA($redirect = false)
{
    ...

    if ($redirect === true)
    {
        // Redirect to functionA page.
    } else {
        // Load view
    }
}

You could also use Javascript to change the form's action page based on the button that was called.