Move submit and cancel handling
Move submit and cancel handling from ConfirmationForm to Form. refs #4439
This commit is contained in:
parent
fa7379adc7
commit
8efbe6f613
|
@ -74,6 +74,24 @@ abstract class Form extends \Zend_Form
|
|||
*/
|
||||
private $sessionId = false;
|
||||
|
||||
/**
|
||||
* Label for submit button
|
||||
*
|
||||
* If omitted, no button will be shown.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $submitLabel;
|
||||
|
||||
/**
|
||||
* Label for cancel button
|
||||
*
|
||||
* If omitted, no button will be shown.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cancelLabel;
|
||||
|
||||
/**
|
||||
* Returns the session ID stored in this form instance
|
||||
* @return mixed
|
||||
|
@ -160,6 +178,14 @@ abstract class Form extends \Zend_Form
|
|||
$this->initCsrfToken();
|
||||
$this->create();
|
||||
|
||||
if ($this->getSubmitLabel()) {
|
||||
$this->addSubmitButton();
|
||||
}
|
||||
|
||||
if ($this->getCancelLabel()) {
|
||||
$this->addCancelButton();
|
||||
}
|
||||
|
||||
// Empty action if not safe
|
||||
if (!$this->getAction() && $this->getRequest()) {
|
||||
$this->setAction($this->getRequest()->getRequestUri());
|
||||
|
@ -169,6 +195,72 @@ abstract class Form extends \Zend_Form
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for cancel label
|
||||
* @param string $cancelLabel
|
||||
*/
|
||||
public function setCancelLabel($cancelLabel)
|
||||
{
|
||||
$this->cancelLabel = $cancelLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for cancel label
|
||||
* @return string
|
||||
*/
|
||||
public function getCancelLabel()
|
||||
{
|
||||
return $this->cancelLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add cancel button to form
|
||||
*/
|
||||
protected function addCancelButton()
|
||||
{
|
||||
$cancelLabel = new \Zend_Form_Element_Reset(
|
||||
array(
|
||||
'name' => 'btn_reset',
|
||||
'label' => $this->getCancelLabel(),
|
||||
'class' => 'btn pull-right'
|
||||
)
|
||||
);
|
||||
$this->addElement($cancelLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for submit label
|
||||
* @param string $submitLabel
|
||||
*/
|
||||
public function setSubmitLabel($submitLabel)
|
||||
{
|
||||
$this->submitLabel = $submitLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for submit label
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitLabel()
|
||||
{
|
||||
return $this->submitLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add submit button to form
|
||||
*/
|
||||
protected function addSubmitButton()
|
||||
{
|
||||
$submitButton = new \Zend_Form_Element_Submit(
|
||||
array(
|
||||
'name' => 'btn_submit',
|
||||
'label' => $this->getSubmitLabel(),
|
||||
'class' => 'btn btn-primary pull-right'
|
||||
)
|
||||
);
|
||||
$this->addElement($submitButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable automatic submission
|
||||
*
|
||||
|
|
|
@ -48,24 +48,6 @@ class ConfirmationForm extends Form
|
|||
*/
|
||||
const DEFAULT_DATE_VALIDATION = 'yyyy-MM-dd hh:ii:ss';
|
||||
|
||||
/**
|
||||
* Label for submit button
|
||||
*
|
||||
* If omitted, no button will be shown.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $submitLabel;
|
||||
|
||||
/**
|
||||
* Label for cancel button
|
||||
*
|
||||
* If omitted, no button will be shown.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cancelLabel;
|
||||
|
||||
/**
|
||||
* Array of messages
|
||||
*
|
||||
|
@ -73,46 +55,6 @@ class ConfirmationForm extends Form
|
|||
*/
|
||||
private $notes = array();
|
||||
|
||||
/**
|
||||
* Setter for cancel label
|
||||
*
|
||||
* @param string $cancelLabel
|
||||
*/
|
||||
public function setCancelLabel($cancelLabel)
|
||||
{
|
||||
$this->cancelLabel = $cancelLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for cancel label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCancelLabel()
|
||||
{
|
||||
return $this->cancelLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for submit label
|
||||
*
|
||||
* @param string $submitLabel
|
||||
*/
|
||||
public function setSubmitLabel($submitLabel)
|
||||
{
|
||||
$this->submitLabel = $submitLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for submit label
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubmitLabel()
|
||||
{
|
||||
return $this->submitLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to stack
|
||||
*
|
||||
|
@ -173,28 +115,6 @@ class ConfirmationForm extends Form
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->getCancelLabel()) {
|
||||
$cancelLabel = new \Zend_Form_Element_Reset(
|
||||
array(
|
||||
'name' => 'btn_reset',
|
||||
'label' => $this->getCancelLabel(),
|
||||
'class' => 'btn pull-right'
|
||||
)
|
||||
);
|
||||
$this->addElement($cancelLabel);
|
||||
}
|
||||
|
||||
if ($this->getSubmitLabel()) {
|
||||
$submitButton = new \Zend_Form_Element_Submit(
|
||||
array(
|
||||
'name' => 'btn_submit',
|
||||
'label' => $this->getSubmitLabel(),
|
||||
'class' => 'btn btn-primary pull-right'
|
||||
)
|
||||
);
|
||||
$this->addElement($submitButton);
|
||||
}
|
||||
|
||||
$this->addElement($this->createInstanceHiddenField());
|
||||
}
|
||||
|
||||
|
|
|
@ -20,17 +20,11 @@ class ConfirmationFormTest extends BaseFormTest
|
|||
|
||||
$form->setRequest($this->getRequest());
|
||||
|
||||
$form->setSubmitLabel('111TEST_SUBMIT');
|
||||
|
||||
$form->setCancelLabel('888TEST_RESET');
|
||||
|
||||
$form->addNote('444 NOTE 1');
|
||||
$form->addNote('555 NOTE 2');
|
||||
$form->buildForm();
|
||||
$content = $form->render($view);
|
||||
|
||||
$this->assertContains('<input type="submit" name="submit" id="submit" value="111TEST_SUBMIT" class="btn btn-primary pull-right">', $content);
|
||||
$this->assertContains('<input type="reset" name="reset" id="reset" value="888TEST_RESET" class="btn pull-right"></dd>', $content);
|
||||
$this->assertContains('<dd id="note_0-element">', $content);
|
||||
$this->assertContains('<dd id="note_1-element">', $content);
|
||||
$this->assertContains('444 NOTE 1</dd>', $content);
|
||||
|
|
Loading…
Reference in New Issue