Jump to:

1999 Posts in 1421 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » setCustomValidationMessage('xy') not showing, SiStr 2.4.5

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 744 Views
  • Gutur
    Avatar
    Community Member
    17 Posts

    setCustomValidationMessage('xy') not showing, SiStr 2.4.5 Link to this post

    Hi there,

    I'm programming a custom form with it's own class. Now, I set a custom validation message but when I tab through the fields and leave the required one blank it always shows me ""this" wird benötigt" (it's german, set to de_DE).
    I know that this message is set in de_DE.js as a general message for required fields, I try to have "this" properly set to the fieldname...
    I'm tinkering for hours now and didn't find anything with search engines or on this forum.
    Any help is appreciated!

    class FormPage extends Page {
       public static $db = array(
       );
       public static $has_one = array(
       );
    }

    class FormPage_Controller extends Page_Controller {
       function OrderForm() {
          $myform = new GBorderForm($this, 'OrderForm');
          return $myform;
       }
    }

    class GBorderForm extends Form {
       function __construct($controller, $name) {
          $Bestellung = new CheckboxField('Bestellung', 'Bestellung');
          $Vertriebspartner = new CheckboxField('Vertriebspartner', 'Vertriebspartner');
          $Interessent = new CheckboxField('Interessent', 'Interessent');
          $Name = new TextField('Name', 'Name');
          $Vorname = new TextField('Vorname', 'Vorname');
          $Firma = new TextField('Firma', 'Firma');
          $StrNr = new TextField('StrNr', 'StrNr');
          $PLZ = new TextField('PLZ', 'PLZ');
          $Ort = new TextField('Ort', 'Ort');
          $Telefon = new TextField('Telefon', 'Telefon');
          $Telefon->setCustomValidationMessage('Bitte Telefonnummer eingeben');
          $Email = new EmailField('Email', 'Email');
          $fields = new FieldSet($Bestellung,$Vertriebspartner,$Interessent,$Name,$Vorname,$Firma,$StrNr,$PLZ,$Ort,$Telefon,$Email);
          $actions = new FieldSet(new FormAction('submit', 'ABSENDEN'));
          $requiredFields = new RequiredFields('Telefon');
          parent::__construct($controller, $name, $fields, $actions, $requiredFields);
       }

       function forTemplate() {
          return $this->renderWith(array(
             $this->class,
             'Form'
          ));
       }

       function submit($data, $form) {
          // TODO sanitize formvalues!
          echo $form->Fields()->dataFieldByName('Telefon')->Value();
          // send mail
       }

    }

    744 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.