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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Form doesn't run desired action


Go to End


766 Views

Avatar
Elzabar

Community Member, 2 Posts

24 September 2012 at 2:04pm

Edited: 24/09/2012 2:36pm

I currently have a form which is supposed to edit an existing member when it is run. However when I press submit, rather than running the function, it runs the default action defined in the form which is a non-existant page (www.urlbase.com/profile/ProfileForm). The code is here:

<?php

class ProfilePage extends Page {
	
}

class ProfilePage_Controller extends Page_Controller {
	
	
	static $allowed_actions = array(
		//'SubmitProfile',
		'ProfileForm'
	);
	
	public function ProfileForm() {
		
		$fields = new FieldList(
			new TextField('FirstName', 'First Name'),
			new EmailField('Email', 'E-mail'),
			new CountryDropdownField('Country', 'Location', null, 'NZ')
		);
		
		$actions = new FieldList(
			new FormAction('SubmitProfile', 'Submit')
		);
		
		//$validator = new RequiredFields('Name');
		
		return new Form($this, 'ProfileForm', $fields, $actions);
	}
	
	public function SubmitProfile($data, $form) {
		
		$member = currentUser();
		$form->saveInto($member);
		$member->write();
		
		Controller::redirect('profile');
	}
}

?>

It doesn't seem to recognise the SubmitProfile function... Can anyone tell me what I'm doing wrong here? Thanks in advance :)

Edit: *facepalm* Solved it. Was trying to use the currentUser function by itself, had to access the Member class first.