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

setFormAction causes error


Go to End


1137 Views

Avatar
Fraser

Community Member, 48 Posts

13 June 2012 at 11:23am

I have a signup form:

function SignupForm() {
		
		$fields = new FieldSet( 
			new TextField("FirstName", "First name"),
			new TextField("Surname"),
			new EmailField("Email", "Email address")
		);	 
      	$submitAction = new FieldSet(new FormAction("SignupAction", "Sign up"));
      	$required = new RequiredFields("Email");
		
		$SignupForm = new Form($this, "SignupForm", $fields, $submitAction, $required); 
		
		
		
		return $SignupForm; 
	}
 
	function SignupAction($data, $form) {
 
		$member = new Member();
		$form->saveInto($member);
 
		$member->write();
 		
		if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")){
			$member->Groups()->add($group);
			Director::redirect('thanks-for-registering/');
		}else{
			Director::redirect('registration-failed/');
		}
 
	}

Which runs fine from the homepage, however it appears on every page and sub page on the site so I need to set the form action.

I have tried adding this:

$SignupForm->setFormAction(Director::baseURL().'home/SignupAction');

before return $SignupForm and I get the following error when I submit the form (from anywhere)

Missing argument 2 for Page_Controller::SignupAction()

function SignupAction($data, $form) {
68  
69 		
70 		$member = new Member();
71 		$form->saveInto($member);
.....

What is going on here?

Thanks