Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Form action uses form name instead?

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

Page: 1
Go to End
Author Topic: 1517 Views
  • Ryan M.
    Community Member
    309 Posts

    Form action uses form name instead? Link to this post

    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);
          return $form;

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

  • Willr
    Forum Moderator
    5503 Posts

    Re: Form action uses form name instead? Link to this post

    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.

  • Ryan M.
    Community Member
    309 Posts

    Re: Form action uses form name instead? Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.