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

Form action uses form name instead?


Go to End


3 Posts   2287 Views

Avatar
Ryan M.

Community Member, 309 Posts

3 February 2011 at 1:17am

Maybe it's just me, because I've been coding all night until the wee hours. =) But I'm confused as to why, when I create a form of my own, it uses the form name as the action url?

function SignupForm() {
		$fields = new FieldSet(
			new EmailField('Email', 'E-mail Address')
		);
		$action = new FieldSet(new FormAction('signup', 'Sign Up'));
		return new Form($this, 'SignupForm', $fields, $action);
	}

will output this in the page:

<form  id="Form_SignupForm" action="/project/home/SignupForm" method="post" enctype="application/x-www-form-urlencoded">

Shouldn't it be this?:

<form  id="Form_SignupForm" action="/project/home/signup" method="post" enctype="application/x-www-form-urlencoded">

I tried doing this instead:

$form = new Form($this, 'SignupForm', $fields, $action);
		$form->setFormAction($this->link('signup'));
		return $form;

but that returns a server error. The former problem just returns you a "page not found" error.

Avatar
Willr

Forum Moderator, 5523 Posts

4 February 2011 at 3:45pm

No it is standard for it to call the Form Name in the URL. When you submit the form it goes back through the form function creating the form object for the save request.

If you want to redirect to a 'nice' url after submitting the form do this in your form processing function.

Avatar
Ryan M.

Community Member, 309 Posts

4 February 2011 at 3:48pm

Ah, no, I wasn't looking to do that. I was just curious about why it processes this way.

I was getting "[Warning] Missing argument 2" errors for the $form variable when using the $allowed_actions array with the form in 2.4.4+ up and this had me mystified because I was setting up the form correctly, but then I read the changelog for 2.4.4 and discovered the change related to forms and $allowed_actions. Worked fine after I tweaked for that.