0
votes

I have multiple submit buttons, such as Preview and Submit. How do I code it to say if I click Preview do this or if I click Submit do that.

I currently have the following set up:

if (HTTP_Request::POST == $this->request->method()):
   try 
   {
      $form->values($this->request->post());
   }
   catch (ORM_Validation_Exception $ex)
   {
      $errors = $ex->errors('models'); 
   }    
endif;

I don't know how to code it to tell it if I clicked the Preview or the Submit button.

Buttons on view page:

echo Form::button('preview', 'Preview', array('type' => 'submit', 'id' => 'preview-button'));
echo Form::submit('submit', 'Submit', array('id' => 'submit-button'));
3

3 Answers

0
votes

Kohana

In Kohana the Form helper has the button and submit methods, they both will accept as first parameter the name attribute and as second the value attribute (for the submit button) or the value attribute must be set explicitly (for the button tag) as a third paramter (view docs). The value you assigned to the name attribute, will appear as a key in the $_POST array and the value you assigned to the value attribute will appear as value in the $_POST array (or Kohana's $this->request->post() which is the same as $_POST).

http://kohanaframework.org/3.2/guide/api/Form#button http://kohanaframework.org/3.2/guide/api/Form#input

So:

Form::submit('submit', 'Submit', array('id' => 'submit-button'));

Will appear in your $this->request->post() method as:

$this->request->post() // contains array('submit' => 'Submit')

PHP Explanation:

<input name="something" type="submit" value="Submit!" />

It will appear in your $_POST array as:

$_POST['something'] // contains "Submit!"
0
votes

Do a var_dump($this->request->post());. There should be a property "submit => preview" or "submit => submit" depending on which button you clicked.

0
votes

In your controller:

$post = $this->request->post();
if (isset($post['preview']))
{
   // Stuff for preview
}
if (isset($post['submit']))
{
   // Stuff for submit
}