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
|
||||
*/
|
||||
public function index() {
|
||||
if($this->Content && $form = $this->Form()) {
|
||||
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
||||
if($content = $this->Content) {
|
||||
$hasLocation = stristr($content, '$UserDefinedForm');
|
||||
|
||||
if($hasLocation) {
|
||||
$content = str_ireplace('$UserDefinedForm', $form->forTemplate(), $this->Content);
|
||||
$replace = ($form = $this->Form()) ? $form->forTemplate() : "";
|
||||
|
||||
$content = str_ireplace('$UserDefinedForm', $replace, $content);
|
||||
|
||||
return array(
|
||||
'Content' => DBField::create('HTMLText', $content),
|
||||
'Form' => ""
|
||||
@ -349,7 +353,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
*/
|
||||
function Form() {
|
||||
$fields = $this->getFormFields();
|
||||
if(!$fields) return false;
|
||||
if(!$fields || !$fields->exists()) return false;
|
||||
|
||||
$actions = $this->getFormActions();
|
||||
|
||||
|
@ -110,10 +110,15 @@ class UserDefinedFormControllerTest extends FunctionalTest {
|
||||
$field->write();
|
||||
|
||||
$controller = new UserDefinedFormControllerTest_Controller($form);
|
||||
|
||||
$fields = $controller->getFormFields();
|
||||
|
||||
$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() {
|
||||
@ -213,7 +218,8 @@ class UserDefinedFormControllerTest_Controller extends UserDefinedForM_Controlle
|
||||
*/
|
||||
function Form() {
|
||||
$form = parent::Form();
|
||||
$form->disableSecurityToken();
|
||||
|
||||
if($form) $form->disableSecurityToken();
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -121,7 +121,8 @@ UserDefinedForm:
|
||||
custom-rules-form:
|
||||
Title: Custom Rules Form
|
||||
Fields: =>EditableCheckbox.checkbox-2, =>EditableTextField.basic-text-2
|
||||
|
||||
empty-form:
|
||||
Title: Empty Form
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user