Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Problem with custom form Template


Go to End


2 Posts   2856 Views

Avatar
somaboy

Community Member, 8 Posts

12 March 2009 at 2:29am

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.

Avatar
brb5548

Community Member, 17 Posts

18 March 2009 at 11:01am

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.