mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-07-11 14:03:51 +02:00
Markdown line endings
This commit is contained in:
parent
b3d4951a88
commit
fe4f0c92e2
@ -64,13 +64,13 @@ Example: Validate postcodes based on the selected country (on the controller).
|
|||||||
public function submit($data, $form) {
|
public function submit($data, $form) {
|
||||||
// At this point, RequiredFields->validate() will have been called already,
|
// At this point, RequiredFields->validate() will have been called already,
|
||||||
// so we can assume that the values exist.
|
// so we can assume that the values exist.
|
||||||
|
|
||||||
// German postcodes need to be five digits
|
// German postcodes need to be five digits
|
||||||
if($data['Country'] == 'de' && isset($data['Postcode']) && strlen($data['Postcode']) != 5) {
|
if($data['Country'] == 'de' && isset($data['Postcode']) && strlen($data['Postcode']) != 5) {
|
||||||
$form->addErrorMessage('Postcode', 'Need five digits for German postcodes', 'bad');
|
$form->addErrorMessage('Postcode', 'Need five digits for German postcodes', 'bad');
|
||||||
return $this->redirectBack();
|
return $this->redirectBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global validation error (not specific to form field)
|
// Global validation error (not specific to form field)
|
||||||
if($data['Country'] == 'IR' && isset($data['Postcode']) && $data['Postcode']) {
|
if($data['Country'] == 'IR' && isset($data['Postcode']) && $data['Postcode']) {
|
||||||
$form->sessionMessage("Ireland doesn't have postcodes!", 'bad');
|
$form->sessionMessage("Ireland doesn't have postcodes!", 'bad');
|
||||||
@ -96,7 +96,7 @@ SilverStripe supports this by allowing to set custom attributes on fields.
|
|||||||
:::php
|
:::php
|
||||||
// Markup contains <input type="text" required />
|
// Markup contains <input type="text" required />
|
||||||
TextField::create('MyText')->setAttribute('required', true);
|
TextField::create('MyText')->setAttribute('required', true);
|
||||||
|
|
||||||
// Markup contains <input type="url" pattern="https?://.+" />
|
// Markup contains <input type="url" pattern="https?://.+" />
|
||||||
TextField::create('MyText')
|
TextField::create('MyText')
|
||||||
->setAttribute('type', 'url')
|
->setAttribute('type', 'url')
|
||||||
@ -111,7 +111,7 @@ These are general purpose attributes, but can be used to hook in your own valida
|
|||||||
// Validate a specific date format (in PHP)
|
// Validate a specific date format (in PHP)
|
||||||
// Markup contains <input type="text" data-dateformat="dd.MM.yyyy" />
|
// Markup contains <input type="text" data-dateformat="dd.MM.yyyy" />
|
||||||
DateField::create('MyDate')->setConfig('dateformat', 'dd.MM.yyyy');
|
DateField::create('MyDate')->setConfig('dateformat', 'dd.MM.yyyy');
|
||||||
|
|
||||||
// Limit extensions on upload (in PHP)
|
// Limit extensions on upload (in PHP)
|
||||||
// Markup contains <input type="file" data-allowed-extensions="jpg,jpeg,gif" />
|
// Markup contains <input type="file" data-allowed-extensions="jpg,jpeg,gif" />
|
||||||
$exts = array('jpg', 'jpeg', 'gif');
|
$exts = array('jpg', 'jpeg', 'gif');
|
||||||
|
Loading…
Reference in New Issue
Block a user