BUGFIX: added exists() check on getFormFields (via Bruce Walter) to prevent fieldless forms. BUGFIX: if built form is empty still strip the $UserDefinedForm token out of the content.

This commit is contained in:
Will Rossiter 2011-03-21 09:14:45 +13:00
parent eac0077cb6
commit fed25ad45b
3 changed files with 18 additions and 7 deletions

View File

@ -324,10 +324,14 @@ class UserDefinedForm_Controller extends Page_Controller {
* @return Array * @return Array
*/ */
public function index() { public function index() {
if($this->Content && $form = $this->Form()) { if($content = $this->Content) {
$hasLocation = stristr($this->Content, '$UserDefinedForm'); $hasLocation = stristr($content, '$UserDefinedForm');
if($hasLocation) { if($hasLocation) {
$content = str_ireplace('$UserDefinedForm', $form->forTemplate(), $this->Content); $replace = ($form = $this->Form()) ? $form->forTemplate() : "";
$content = str_ireplace('$UserDefinedForm', $replace, $content);
return array( return array(
'Content' => DBField::create('HTMLText', $content), 'Content' => DBField::create('HTMLText', $content),
'Form' => "" 'Form' => ""
@ -349,7 +353,7 @@ class UserDefinedForm_Controller extends Page_Controller {
*/ */
function Form() { function Form() {
$fields = $this->getFormFields(); $fields = $this->getFormFields();
if(!$fields) return false; if(!$fields || !$fields->exists()) return false;
$actions = $this->getFormActions(); $actions = $this->getFormActions();

View File

@ -110,10 +110,15 @@ class UserDefinedFormControllerTest extends FunctionalTest {
$field->write(); $field->write();
$controller = new UserDefinedFormControllerTest_Controller($form); $controller = new UserDefinedFormControllerTest_Controller($form);
$fields = $controller->getFormFields(); $fields = $controller->getFormFields();
$this->assertEquals($fields->First()->RightTitle(), "Right Title"); $this->assertEquals($fields->First()->RightTitle(), "Right Title");
// test empty form
$emptyForm = $this->objFromFixture('UserDefinedForm', 'empty-form');
$controller = new UserDefinedFormControllerTest_Controller($emptyForm);
$this->assertFalse($controller->Form());
} }
function testGetFormActions() { function testGetFormActions() {
@ -213,7 +218,8 @@ class UserDefinedFormControllerTest_Controller extends UserDefinedForM_Controlle
*/ */
function Form() { function Form() {
$form = parent::Form(); $form = parent::Form();
$form->disableSecurityToken();
if($form) $form->disableSecurityToken();
return $form; return $form;
} }

View File

@ -121,7 +121,8 @@ UserDefinedForm:
custom-rules-form: custom-rules-form:
Title: Custom Rules Form Title: Custom Rules Form
Fields: =>EditableCheckbox.checkbox-2, =>EditableTextField.basic-text-2 Fields: =>EditableCheckbox.checkbox-2, =>EditableTextField.basic-text-2
empty-form:
Title: Empty Form