5116 Posts in 1525 Topics by 1118 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1559 Views |
-
Custom form validation messages

24 March 2009 at 3:30am
Hi.
In order to custom the validation messages (javascript ones or others) the only way is to mess up with sapphire files ?
aka Sapphire/Forms/EmailField.php and/or Sapphire/Lang/en_EN.php ?Any way to properly override the $lang array ?
Thanks for any hint.
Be safe. -
Re: Custom form validation messages

27 March 2009 at 10:18am
I've been looking for that as well, but I'm afraid that's the only solution.
Still hoping I'm wrong -
Re: Custom form validation messages

27 March 2009 at 1:23pm Last edited: 1 April 2009 6:46am
So, I managed to modify texts and translations from within my controller, and thus avoiding to mess up with Sapphire.
It's not an elegant solution but it works.There are 2 issues :
- It's not possible to set a specific required-validation text for each field. A global "%s is required" is the only option I'm aware of.
- For the Javascript required-validations, you have to target the field by their Html IDs. Those IDs can change if you modify the form in the CMS.class ContactPage_Controller extends UserDefinedForm_Controller {
public function init() {
parent::init();global $lang;
// Php and Javascript formating-validations for email fields
$lang['en_US']['EmailField']['VALIDATION'] = $lang['en_US']['EmailField']['VALIDATIONJS'] = 'It seams your email address is not really valid.';// Php required-validations
$lang['en_US']['Form']['FIELDISREQUIRED'] = 'Could you please fill the field %s because it\'s important to us';// Javascript required-validations for each field
Requirements::customScript( "
if( typeof Behaviour != 'undefined') {
Behaviour.register({
'#Form_Form_EditableTextField2' : { requiredErrorMsg: 'Knowing who you are is important to us. Please give us a name, and your company\'s one too, if applicable.' },
'#Form_Form_EditableEmailField4' : { requiredErrorMsg: 'Please give us your email address, or we sadly won\'t be able ton get in touch with you.' }
}); // register()
} // if != undefined
"); // customScript()
} // init()
} // ContactPage_Controller
| 1559 Views | ||
|
Page:
1
|
Go to Top |


