2008-04-06 05:52:14 +02:00
|
|
|
<?php
|
2008-06-15 15:33:53 +02:00
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2008-10-06 16:58:01 +02:00
|
|
|
class FormTest extends FunctionalTest {
|
2008-04-06 05:52:14 +02:00
|
|
|
|
2011-03-30 08:49:11 +02:00
|
|
|
static $fixture_file = 'FormTest.yml';
|
2010-04-12 04:03:16 +02:00
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'FormTest_Player',
|
|
|
|
'FormTest_Team',
|
|
|
|
);
|
2008-10-07 19:23:50 +02:00
|
|
|
|
2008-04-06 05:52:14 +02:00
|
|
|
public function testLoadDataFromRequest() {
|
|
|
|
$form = new Form(
|
|
|
|
new Controller(),
|
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2008-04-06 05:52:14 +02:00
|
|
|
new TextField('key1'),
|
|
|
|
new TextField('namespace[key2]'),
|
|
|
|
new TextField('namespace[key3][key4]'),
|
|
|
|
new TextField('othernamespace[key5][key6][key7]')
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList()
|
2008-04-06 05:52:14 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// url would be ?key1=val1&namespace[key2]=val2&namespace[key3][key4]=val4&othernamespace[key5][key6][key7]=val7
|
|
|
|
$requestData = array(
|
|
|
|
'key1' => 'val1',
|
|
|
|
'namespace' => array(
|
|
|
|
'key2' => 'val2',
|
|
|
|
'key3' => array(
|
|
|
|
'key4' => 'val4',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'othernamespace' => array(
|
|
|
|
'key5' => array(
|
|
|
|
'key6' =>array(
|
|
|
|
'key7' => 'val7'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$form->loadDataFrom($requestData);
|
|
|
|
|
|
|
|
$fields = $form->Fields();
|
|
|
|
$this->assertEquals($fields->fieldByName('key1')->Value(), 'val1');
|
|
|
|
$this->assertEquals($fields->fieldByName('namespace[key2]')->Value(), 'val2');
|
|
|
|
$this->assertEquals($fields->fieldByName('namespace[key3][key4]')->Value(), 'val4');
|
|
|
|
$this->assertEquals($fields->fieldByName('othernamespace[key5][key6][key7]')->Value(), 'val7');
|
|
|
|
}
|
|
|
|
|
2008-10-07 19:44:12 +02:00
|
|
|
public function testLoadDataFromUnchangedHandling() {
|
|
|
|
$form = new Form(
|
|
|
|
new Controller(),
|
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2008-10-07 19:44:12 +02:00
|
|
|
new TextField('key1'),
|
|
|
|
new TextField('key2')
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList()
|
2008-10-07 19:44:12 +02:00
|
|
|
);
|
|
|
|
$form->loadDataFrom(array(
|
|
|
|
'key1' => 'save',
|
|
|
|
'key2' => 'dontsave',
|
|
|
|
'key2_unchanged' => '1'
|
|
|
|
));
|
|
|
|
$this->assertEquals(
|
|
|
|
$form->getData(),
|
|
|
|
array(
|
|
|
|
'key1' => 'save',
|
|
|
|
'key2' => null,
|
|
|
|
),
|
|
|
|
'loadDataFrom() doesnt save a field if a matching "<fieldname>_unchanged" flag is set'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-10-07 19:23:50 +02:00
|
|
|
public function testLoadDataFromObject() {
|
|
|
|
$form = new Form(
|
|
|
|
new Controller(),
|
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2008-10-16 15:26:50 +02:00
|
|
|
new HeaderField('MyPlayerHeader','My Player'),
|
2008-10-07 19:23:50 +02:00
|
|
|
new TextField('Name'), // appears in both Player and Team
|
|
|
|
new TextareaField('Biography'),
|
|
|
|
new DateField('Birthday'),
|
|
|
|
new NumericField('BirthdayYear') // dynamic property
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList()
|
2008-10-07 19:23:50 +02:00
|
|
|
);
|
|
|
|
|
2008-10-09 16:40:13 +02:00
|
|
|
$captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
|
|
|
|
$form->loadDataFrom($captainWithDetails);
|
2008-10-07 19:23:50 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$form->getData(),
|
|
|
|
array(
|
2008-10-09 16:40:13 +02:00
|
|
|
'Name' => 'Captain Details',
|
2008-10-07 19:23:50 +02:00
|
|
|
'Biography' => 'Bio 1',
|
|
|
|
'Birthday' => '1982-01-01',
|
|
|
|
'BirthdayYear' => '1982',
|
|
|
|
),
|
|
|
|
'LoadDataFrom() loads simple fields and dynamic getters'
|
|
|
|
);
|
|
|
|
|
2008-10-09 16:40:13 +02:00
|
|
|
$captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
|
|
|
|
$form->loadDataFrom($captainNoDetails);
|
2008-10-07 19:23:50 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$form->getData(),
|
|
|
|
array(
|
2008-10-09 16:40:13 +02:00
|
|
|
'Name' => 'Captain No Details',
|
|
|
|
'Biography' => null,
|
|
|
|
'Birthday' => null,
|
|
|
|
'BirthdayYear' => 0,
|
|
|
|
),
|
|
|
|
'LoadNonBlankDataFrom() loads only fields with values, and doesnt overwrite existing values'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLoadDataFromClearMissingFields() {
|
|
|
|
$form = new Form(
|
|
|
|
new Controller(),
|
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2008-10-16 15:26:50 +02:00
|
|
|
new HeaderField('MyPlayerHeader','My Player'),
|
2008-10-09 16:40:13 +02:00
|
|
|
new TextField('Name'), // appears in both Player and Team
|
|
|
|
new TextareaField('Biography'),
|
|
|
|
new DateField('Birthday'),
|
|
|
|
new NumericField('BirthdayYear'), // dynamic property
|
|
|
|
$unrelatedField = new TextField('UnrelatedFormField')
|
|
|
|
//new CheckboxSetField('Teams') // relation editing
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList()
|
2008-10-09 16:40:13 +02:00
|
|
|
);
|
|
|
|
$unrelatedField->setValue("random value");
|
|
|
|
|
|
|
|
$captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
|
|
|
|
$captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
|
|
|
|
$form->loadDataFrom($captainWithDetails);
|
|
|
|
$this->assertEquals(
|
|
|
|
$form->getData(),
|
|
|
|
array(
|
|
|
|
'Name' => 'Captain Details',
|
2008-10-07 19:23:50 +02:00
|
|
|
'Biography' => 'Bio 1',
|
|
|
|
'Birthday' => '1982-01-01',
|
2008-10-09 16:40:13 +02:00
|
|
|
'BirthdayYear' => '1982',
|
|
|
|
'UnrelatedFormField' => 'random value',
|
2008-10-07 19:23:50 +02:00
|
|
|
),
|
2008-10-09 16:40:13 +02:00
|
|
|
'LoadDataFrom() doesnt overwrite fields not found in the object'
|
2008-10-07 19:23:50 +02:00
|
|
|
);
|
|
|
|
|
2008-10-09 16:40:13 +02:00
|
|
|
$captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
|
|
|
|
$team2 = $this->objFromFixture('FormTest_Team', 'team2');
|
|
|
|
$form->loadDataFrom($captainWithDetails);
|
|
|
|
$form->loadDataFrom($team2, true);
|
2008-10-07 19:23:50 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
$form->getData(),
|
|
|
|
array(
|
2008-10-09 16:40:13 +02:00
|
|
|
'Name' => 'Team 2',
|
2008-10-07 19:23:50 +02:00
|
|
|
'Biography' => '',
|
|
|
|
'Birthday' => '',
|
|
|
|
'BirthdayYear' => 0,
|
2008-10-09 16:40:13 +02:00
|
|
|
'UnrelatedFormField' => null,
|
2008-10-07 19:23:50 +02:00
|
|
|
),
|
2008-10-09 16:40:13 +02:00
|
|
|
'LoadDataFrom() overwrites fields not found in the object with $clearMissingFields=true'
|
2008-10-07 19:23:50 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-10-06 16:58:01 +02:00
|
|
|
public function testFormMethodOverride() {
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$form->setFormMethod('GET');
|
2012-01-02 15:03:35 +01:00
|
|
|
$this->assertNull($form->Fields()->dataFieldByName('_method'));
|
2008-10-06 16:58:01 +02:00
|
|
|
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$form->setFormMethod('PUT');
|
2012-01-02 15:03:35 +01:00
|
|
|
$this->assertEquals($form->Fields()->dataFieldByName('_method')->Value(), 'put',
|
2008-10-06 16:58:01 +02:00
|
|
|
'PUT override in forms has PUT in hiddenfield'
|
|
|
|
);
|
|
|
|
$this->assertEquals($form->FormMethod(), 'post',
|
|
|
|
'PUT override in forms has POST in <form> tag'
|
|
|
|
);
|
|
|
|
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$form->setFormMethod('DELETE');
|
2012-01-02 15:03:35 +01:00
|
|
|
$this->assertEquals($form->Fields()->dataFieldByName('_method')->Value(), 'delete',
|
2008-10-06 16:58:01 +02:00
|
|
|
'PUT override in forms has PUT in hiddenfield'
|
|
|
|
);
|
|
|
|
$this->assertEquals($form->FormMethod(), 'post',
|
|
|
|
'PUT override in forms has POST in <form> tag'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-10-14 23:37:51 +02:00
|
|
|
function testSessionValidationMessage() {
|
|
|
|
$this->get('FormTest_Controller');
|
|
|
|
|
2012-04-20 05:02:43 +02:00
|
|
|
$response = $this->post(
|
|
|
|
'FormTest_Controller/Form',
|
2008-10-14 23:37:51 +02:00
|
|
|
array(
|
|
|
|
'Email' => 'invalid',
|
|
|
|
// leaving out "Required" field
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertPartialMatchBySelector(
|
|
|
|
'#Email span.message',
|
|
|
|
array(
|
2012-06-01 03:13:06 +02:00
|
|
|
'Please enter an email address'
|
2008-10-14 23:37:51 +02:00
|
|
|
),
|
|
|
|
'Formfield validation shows note on field if invalid'
|
|
|
|
);
|
|
|
|
$this->assertPartialMatchBySelector(
|
|
|
|
'#SomeRequiredField span.required',
|
|
|
|
array(
|
2012-06-01 03:13:06 +02:00
|
|
|
'"SomeRequiredField" is required'
|
2008-10-14 23:37:51 +02:00
|
|
|
),
|
|
|
|
'Required fields show a notification on field when left blank'
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSessionSuccessMessage() {
|
|
|
|
$this->get('FormTest_Controller');
|
|
|
|
|
2012-04-20 05:02:43 +02:00
|
|
|
$response = $this->post(
|
|
|
|
'FormTest_Controller/Form',
|
2008-10-14 23:37:51 +02:00
|
|
|
array(
|
|
|
|
'Email' => 'test@test.com',
|
|
|
|
'SomeRequiredField' => 'test',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertPartialMatchBySelector(
|
|
|
|
'#Form_Form_error',
|
|
|
|
array(
|
|
|
|
'Test save was successful'
|
|
|
|
),
|
|
|
|
'Form->sessionMessage() shows up after reloading the form'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-12-05 09:22:57 +01:00
|
|
|
function testGloballyDisabledSecurityTokenInheritsToNewForm() {
|
|
|
|
SecurityToken::enable();
|
|
|
|
|
|
|
|
$form1 = $this->getStubForm();
|
2012-05-09 12:43:22 +02:00
|
|
|
$this->assertInstanceOf('SecurityToken', $form1->getSecurityToken());
|
2010-12-05 09:22:57 +01:00
|
|
|
|
|
|
|
SecurityToken::disable();
|
|
|
|
|
|
|
|
$form2 = $this->getStubForm();
|
2012-05-09 12:43:22 +02:00
|
|
|
$this->assertInstanceOf('NullSecurityToken', $form2->getSecurityToken());
|
2010-12-05 09:22:57 +01:00
|
|
|
|
|
|
|
SecurityToken::enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDisableSecurityTokenDoesntAddTokenFormField() {
|
|
|
|
SecurityToken::enable();
|
|
|
|
|
|
|
|
$formWithToken = $this->getStubForm();
|
2012-05-09 12:43:22 +02:00
|
|
|
$this->assertInstanceOf(
|
2010-12-05 09:22:57 +01:00
|
|
|
'HiddenField',
|
|
|
|
$formWithToken->Fields()->fieldByName(SecurityToken::get_default_name()),
|
|
|
|
'Token field added by default'
|
|
|
|
);
|
|
|
|
|
|
|
|
$formWithoutToken = $this->getStubForm();
|
|
|
|
$formWithoutToken->disableSecurityToken();
|
|
|
|
$this->assertNull(
|
|
|
|
$formWithoutToken->Fields()->fieldByName(SecurityToken::get_default_name()),
|
|
|
|
'Token field not added if disableSecurityToken() is set'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDisableSecurityTokenAcceptsSubmissionWithoutToken() {
|
|
|
|
SecurityToken::enable();
|
|
|
|
|
|
|
|
$response = $this->get('FormTest_ControllerWithSecurityToken');
|
|
|
|
// can't use submitForm() as it'll automatically insert SecurityID into the POST data
|
|
|
|
$response = $this->post(
|
|
|
|
'FormTest_ControllerWithSecurityToken/Form',
|
|
|
|
array(
|
|
|
|
'Email' => 'test@test.com',
|
|
|
|
'action_doSubmit' => 1
|
|
|
|
// leaving out security token
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals(400, $response->getStatusCode(), 'Submission fails without security token');
|
|
|
|
|
|
|
|
$response = $this->get('FormTest_ControllerWithSecurityToken');
|
|
|
|
$tokenEls = $this->cssParser()->getBySelector('#Form_Form_SecurityID');
|
|
|
|
$this->assertEquals(
|
|
|
|
1,
|
|
|
|
count($tokenEls),
|
|
|
|
'Token form field added for controller without disableSecurityToken()'
|
|
|
|
);
|
|
|
|
$token = (string)$tokenEls[0];
|
|
|
|
$response = $this->submitForm(
|
|
|
|
'Form_Form',
|
|
|
|
null,
|
|
|
|
array(
|
|
|
|
'Email' => 'test@test.com',
|
|
|
|
'SecurityID' => $token
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertEquals(200, $response->getStatusCode(), 'Submission suceeds with security token');
|
|
|
|
}
|
|
|
|
|
2010-12-05 09:30:32 +01:00
|
|
|
function testEnableSecurityToken() {
|
|
|
|
SecurityToken::disable();
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$this->assertFalse($form->getSecurityToken()->isEnabled());
|
|
|
|
$form->enableSecurityToken();
|
|
|
|
$this->assertTrue($form->getSecurityToken()->isEnabled());
|
|
|
|
|
|
|
|
SecurityToken::disable(); // restore original
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDisableSecurityToken() {
|
|
|
|
SecurityToken::enable();
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$this->assertTrue($form->getSecurityToken()->isEnabled());
|
|
|
|
$form->disableSecurityToken();
|
|
|
|
$this->assertFalse($form->getSecurityToken()->isEnabled());
|
|
|
|
|
|
|
|
SecurityToken::disable(); // restore original
|
|
|
|
}
|
2011-12-26 08:36:24 +01:00
|
|
|
|
|
|
|
public function testEncType() {
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$this->assertEquals('application/x-www-form-urlencoded', $form->getEncType());
|
|
|
|
|
|
|
|
$form->setEncType(Form::ENC_TYPE_MULTIPART);
|
|
|
|
$this->assertEquals('multipart/form-data', $form->getEncType());
|
|
|
|
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$form->Fields()->push(new FileField(null));
|
|
|
|
$this->assertEquals('multipart/form-data', $form->getEncType());
|
|
|
|
|
|
|
|
$form->setEncType(Form::ENC_TYPE_URLENCODED);
|
|
|
|
$this->assertEquals('application/x-www-form-urlencoded', $form->getEncType());
|
|
|
|
}
|
|
|
|
|
2011-12-22 18:05:20 +01:00
|
|
|
|
|
|
|
function testAttributes() {
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
$form->setAttribute('foo', 'bar');
|
|
|
|
$this->assertEquals('bar', $form->getAttribute('foo'));
|
|
|
|
$attrs = $form->getAttributes();
|
|
|
|
$this->assertArrayHasKey('foo', $attrs);
|
|
|
|
$this->assertEquals('bar', $attrs['foo']);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAttributesHTML() {
|
|
|
|
$form = $this->getStubForm();
|
|
|
|
|
|
|
|
$form->setAttribute('foo', 'bar');
|
|
|
|
$this->assertContains('foo="bar"', $form->getAttributesHTML());
|
|
|
|
|
|
|
|
$form->setAttribute('foo', null);
|
|
|
|
$this->assertNotContains('foo="bar"', $form->getAttributesHTML());
|
|
|
|
|
|
|
|
$form->setAttribute('foo', true);
|
|
|
|
$this->assertContains('foo="foo"', $form->getAttributesHTML());
|
|
|
|
|
|
|
|
$form->setAttribute('one', 1);
|
|
|
|
$form->setAttribute('two', 2);
|
|
|
|
$form->setAttribute('three', 3);
|
|
|
|
$this->assertNotContains('one="1"', $form->getAttributesHTML('one', 'two'));
|
|
|
|
$this->assertNotContains('two="2"', $form->getAttributesHTML('one', 'two'));
|
|
|
|
$this->assertContains('three="3"', $form->getAttributesHTML('one', 'two'));
|
|
|
|
}
|
|
|
|
|
2008-10-06 16:58:01 +02:00
|
|
|
protected function getStubForm() {
|
|
|
|
return new Form(
|
2011-12-22 18:05:20 +01:00
|
|
|
new FormTest_Controller(),
|
2008-10-06 16:58:01 +02:00
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(new TextField('key1')),
|
|
|
|
new FieldList()
|
2008-10-06 16:58:01 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-04-06 05:52:14 +02:00
|
|
|
}
|
2008-10-07 19:23:50 +02:00
|
|
|
|
|
|
|
class FormTest_Player extends DataObject implements TestOnly {
|
|
|
|
static $db = array(
|
|
|
|
'Name' => 'Varchar',
|
|
|
|
'Biography' => 'Text',
|
|
|
|
'Birthday' => 'Date'
|
|
|
|
);
|
|
|
|
|
|
|
|
static $belongs_many_many = array(
|
|
|
|
'Teams' => 'FormTest_Team'
|
|
|
|
);
|
|
|
|
|
|
|
|
static $has_one = array(
|
|
|
|
'FavouriteTeam' => 'FormTest_Team',
|
|
|
|
);
|
|
|
|
|
|
|
|
public function getBirthdayYear() {
|
|
|
|
return ($this->Birthday) ? date('Y', strtotime($this->Birthday)) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class FormTest_Team extends DataObject implements TestOnly {
|
|
|
|
static $db = array(
|
|
|
|
'Name' => 'Varchar',
|
|
|
|
'Region' => 'Varchar',
|
|
|
|
);
|
|
|
|
|
|
|
|
static $many_many = array(
|
|
|
|
'Players' => 'FormTest_Player'
|
|
|
|
);
|
|
|
|
}
|
2008-10-14 23:37:51 +02:00
|
|
|
|
2011-02-13 23:14:51 +01:00
|
|
|
class FormTest_Controller extends Controller implements TestOnly {
|
2008-10-14 23:37:51 +02:00
|
|
|
static $url_handlers = array(
|
|
|
|
'$Action//$ID/$OtherID' => "handleAction",
|
|
|
|
);
|
|
|
|
|
|
|
|
protected $template = 'BlankPage';
|
|
|
|
|
2009-10-11 02:07:16 +02:00
|
|
|
function Link($action = null) {
|
|
|
|
return Controller::join_links('FormTest_Controller', $this->request->latestParam('Action'), $this->request->latestParam('ID'), $action);
|
2008-10-14 23:37:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Form() {
|
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2008-10-14 23:37:51 +02:00
|
|
|
new EmailField('Email'),
|
|
|
|
new TextField('SomeRequiredField'),
|
|
|
|
new CheckboxSetField('Boxes', null, array('1'=>'one','2'=>'two'))
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2008-10-14 23:37:51 +02:00
|
|
|
new FormAction('doSubmit')
|
|
|
|
),
|
|
|
|
new RequiredFields(
|
|
|
|
'Email',
|
|
|
|
'SomeRequiredField'
|
|
|
|
)
|
|
|
|
);
|
2010-12-05 09:22:57 +01:00
|
|
|
|
|
|
|
// Disable CSRF protection for easier form submission handling
|
|
|
|
$form->disableSecurityToken();
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FormWithSecurityToken() {
|
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'FormWithSecurityToken',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2010-12-05 09:22:57 +01:00
|
|
|
new EmailField('Email')
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2010-12-05 09:22:57 +01:00
|
|
|
new FormAction('doSubmit')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSubmit($data, $form, $request) {
|
|
|
|
$form->sessionMessage('Test save was successful', 'good');
|
|
|
|
return $this->redirectBack();
|
|
|
|
}
|
2011-03-18 03:01:09 +01:00
|
|
|
|
2012-03-27 06:04:11 +02:00
|
|
|
function getViewer($action = null) {
|
2011-03-23 04:32:24 +01:00
|
|
|
return new SSViewer('BlankPage');
|
2011-03-18 03:01:09 +01:00
|
|
|
}
|
|
|
|
|
2010-12-05 09:22:57 +01:00
|
|
|
}
|
|
|
|
|
2011-02-13 23:14:51 +01:00
|
|
|
class FormTest_ControllerWithSecurityToken extends Controller implements TestOnly {
|
2010-12-05 09:22:57 +01:00
|
|
|
static $url_handlers = array(
|
|
|
|
'$Action//$ID/$OtherID' => "handleAction",
|
|
|
|
);
|
|
|
|
|
|
|
|
protected $template = 'BlankPage';
|
|
|
|
|
|
|
|
function Link($action = null) {
|
|
|
|
return Controller::join_links('FormTest_ControllerWithSecurityToken', $this->request->latestParam('Action'), $this->request->latestParam('ID'), $action);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Form() {
|
|
|
|
$form = new Form(
|
|
|
|
$this,
|
|
|
|
'Form',
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2010-12-05 09:22:57 +01:00
|
|
|
new EmailField('Email')
|
|
|
|
),
|
2011-05-11 09:51:54 +02:00
|
|
|
new FieldList(
|
2010-12-05 09:22:57 +01:00
|
|
|
new FormAction('doSubmit')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2008-10-14 23:37:51 +02:00
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doSubmit($data, $form, $request) {
|
|
|
|
$form->sessionMessage('Test save was successful', 'good');
|
|
|
|
return $this->redirectBack();
|
|
|
|
}
|
2011-03-18 03:01:09 +01:00
|
|
|
|
2012-03-27 06:04:11 +02:00
|
|
|
function getViewer($action = null) {
|
2011-03-23 04:32:24 +01:00
|
|
|
return new SSViewer('BlankPage');
|
2011-03-18 03:01:09 +01:00
|
|
|
}
|
2008-10-14 23:37:51 +02:00
|
|
|
}
|
|
|
|
|
2012-05-22 07:13:05 +02:00
|
|
|
Config::inst()->update('Director', 'rules', array(
|
|
|
|
'FormTest_Controller' => 'FormTest_Controller'
|
2008-10-14 23:37:51 +02:00
|
|
|
));
|
2012-05-22 07:13:05 +02:00
|
|
|
|