Welcome Guest, Not a member yet? Register   Sign In
Carry form element value to button or link
#1

[eluser]Unknown[/eluser]
I have a form with radio buttons to select. I have 2 buttons: 1 is "Create New STyle", other is "List selected Style." I like to get the value of radio button value into the link of these 2 buttons.

For example, if radio A is selected, "createAStyle.php" or "viewAStyle.php" should be opened after a button is clicked.

Is there anyway to 2 buttons for 1 form? How to concatenate the value into the link?
#2

[eluser]Michael Wales[/eluser]
Make the form go to the same controller and give your submit buttons name attributes. In that controller, determine which button was pressed and load that particular view.

You could also redirect() from the form processing controller, but you would lose the value of your radio field.
#3

[eluser]eedfwChris[/eluser]
You could only use redirect if you are not trying to submit other form data fields (because redirect doesn't send the post variables AGAIN). So you could do:
Code:
function do_style()
{
    switch ($this->input->post($radio_box_value)
    {
        case 'create':
            $this->create_style();
            break;
        case 'view':
            $this->view_style();
    }
}

function create_style()
{
    ...
}

function view_style()
{
    ...
}
The disadvantage to this is that you don't get a specific URL/URI like it may be ideal. For example, you have do_style() which has no real meaning but you may idealy want to have create_style() instead. This, again, can be solved by using redirect() but this doesn't allow you to work with POST data in the redirect.

Also, keep in mind the redirect kinda makes the browser history screwy so only use it when you are certain it should exist and the user is unlikely to hit "back" in their browser.




Theme © iAndrew 2016 - Forum software by © MyBB