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.

Form Questions

Form action uses form name instead?


Reply

3 Posts   1530 Views

Avatar
Ryan M.

3 February 2011 at 1:17am Community Member, 309 Posts

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

4 February 2011 at 3:45pm Forum Moderator, 5511 Posts

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.

4 February 2011 at 3:48pm Community Member, 309 Posts

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.