Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Problem with custom form Template

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

Page: 1
Go to End
Author Topic: 1710 Views
  • somaboy
    Avatar
    Community Member
    8 Posts

    Problem with custom form Template Link to this post

    Hi,

    I'm trying to render a custom form using renderWith().

    I'm still quite new to SS, so the data model isn't entirely clear to me yet. Here's what I have so far:

       class SignupForm extends Form
       {
          function __construct($controller, $name)
          {
              $fields = new FieldSet(
                   new TextField("FirstName", "voornaam"),
                   new TextField("Surname,", 'naam'),
                   new DateField('BirthDate', 'geboortedatum'),
                   new EmailField("Email", "e-mail adres"),
                   new PhoneNumberField('Mobile', 'gsm'),
                   new PhoneNumberField('Fax', 'fax'),
                   new TextField('Street', 'straat'),
                   new TextField('Number', 'huisnummer'),
                   new TextField('Zip', 'postcode'),
                   new TextField('City', 'gemeente')
              );
             
              $actions = new FieldSet("SignupAction", "word lid");
             
             
              parent::__construct($controller, $name, $fields, $actions);
          }
          
          function forTemplate() {
              return $this->renderWith(array(
                    $this->class,
                    'Form'
              ));
          }
          
          function submit($data, $form) {
             $submission = new SignupFormSubmission();
             $form->saveInto($submission);
             $submission->write();
             
             Director::redirectBack();
          }
       
       }

    Now, how do i make it actually render, using my custom SignupForm template? I guess I need to create a Model and controller for the page, but what should be in those classes? Also, how do i integrate validation?

    Thanks a million.

  • brb5548
    Avatar
    Community Member
    17 Posts

    Re: Problem with custom form Template Link to this post

    if i understand your question, you should be able to comment the 'Director::redirectBack();' line in the submit function and use
    $this->renderWith('SignupForm');
    to render with your SignupForm.ss template.

    1710 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.