Welcome Guest, Not a member yet? Register   Sign In
Two "submit" inputs
#1

[eluser]Lionel H[/eluser]
Hello,

I have a question which I didn't find any answer for in the forum : I have a form (a newsletter), and I want to use two submit inputs, one for previewing the newsletter, one for sending it.
I found this solution, but I have the feeling it's not the best way :

the view
Code:
...html code...

<?= form_open('newsletter/send') ?>

...html code...

<?= form_submit('send', 'Envoyer') ?>
<?= form_submit('preview', 'Prévisualiser') ?>

...html code...

the controller
Code:
function send()
{
    $data = $_POST;
    if(isset($data['send'])):
        # code for sending the newsletter
    elseif(isset($data['preview'])):
        $this->load->view('includes/newsletter');
    endif;
}

Ideally, I'd like each submit to send to its own controller ; does anybody know how to do this ? :-)
#2

[eluser]Phil Sturgeon[/eluser]
Other than using javascript to change the form action on submit, theres no real way of doing this. You could use some combination of session variables and a redirect, but thats a bit dirty.
#3

[eluser]Lionel H[/eluser]
Thank you thepyromaniac. So here's the code I will use :
Code:
function preview()
{
    $data = $_POST;
    
    if(isset($data['preview'])):
        $this->load->view('includes/newsletterpreview');
    else:
        $this->db->insert('newsletter', $data);
        redirect('newsletter/send');
    endif;
}

function send()
{
    # code for sending the newsletter
}




Theme © iAndrew 2016 - Forum software by © MyBB