mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
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:
parent
eac0077cb6
commit
fed25ad45b
@ -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();
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user