CodeIgniter Forums

Full Version: URI change when calling controller functions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[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>

El Forum

[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.
Pages: 1 2