Form post button with variable

Permalink
Hi there,

In the dashboard i have a form that is using the interface helper which posts my form.
I want to add a second form button that gives the user a different option. I need to pass a variable through with the second button so i know which button has been clicked before processing my form.

I have tried adding an extra value in the arguments section after 'style (btn)' but i get an error. How do i pass a variable through on the button..?

This works (but no variable assigned)
<?php print $ih->submit('Save', 'property-form','left','btn'); ?>
This errors
<?php print $ih->submit('Second option', 'property-form','left','btn',$variable); ?>

 
lostPixels replied on at Permalink Best Answer Reply
I recently had to figure this out too. Here's what I did...

In my view.php where I'm building my form:

<form method="post" action="<?php echo $this->action('edit?cID='.$event->getCollectionID()); ?>" style="padding-top:11px; margin:0">
                           <?php echo $ih->submit('view', '', '', 'info'); ?>
                           <?php echo $ih->submit('update', '', '', 'info'); ?>            
                           <?php echo $ih->submit('delete', '', '', 'danger'); ?>                     
                        </form>


And then in my controller:

public function edit()
   {
      if(isset($_REQUEST['cID']))
      {
         $cID = intval($_REQUEST['cID']);
         if($_REQUEST['ccm-submit-button'] == 'delete')
         {
            $this->delete($cID);
         }
         else if($_REQUEST['ccm-submit-button'] == 'update')
         {
            $this->update($cID);
         }
         else if($_REQUEST['ccm-submit-button'] == 'view')
         {


So as you can see, edit is being called for all submit buttons, but based on their name the function changes.
obaudains replied on at Permalink Reply
Absolute hero!

Thank you.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.