Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8411393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:24:40+00:00 2026-06-10T00:24:40+00:00

I have a signup form: function SignupForm() { $fields = new FieldSet( new TextField(FirstName,

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:24:41+00:00Added an answer on June 10, 2026 at 12:24 am

    this error occurs because of how silverstripe handles forms

    silverstripe does never redirect to the form action, it always redirects to the form it self, so if your form is

    function SignupForm() {
       ...
       return new Form(...);
    }
    

    then silverstripe will always redirect back to this function, so if you are on mysite.com/foobar/ the form will go to mysite.com/foobar/SignupForm
    And then, it will call ->SignupAction(), so SignupAction is never i the url.

    This is how I would do it:

    <?php
    
    class Page extends SiteTree {
    }
    
    class Page_Controller extends ContentController {
        public static $allowed_actions = array(
            'SignupForm',
            'registeringThanks',
            'registrationFailed',
        );
        public function SignupForm() {
            $fields = new FieldSet(
                new TextField("FirstName", "First name"),
                new TextField("Surname"),
                new EmailField("Email", "Email address")
            );
            $actions = new FieldSet(
                new FormAction("SignupAction", "Sign up")
            );
            $validator = new RequiredFields("Email");
            // use __FUNCTION__ here so we don't have to type SignupForm again
            return new Form($this, __FUNCTION__, $fields, $actions, $validator);
        }
        public function SignupAction($data, Form $form, SS_HTTPRequest $request) {
            $member = new Member();
            $form->saveInto($member);
            $member->write();
            $home = SiteTree::get_by_link(null);
            // instead of using $group = DataObject::get_one('Group', "ID = {$home->defaultGroupID}");
            // we can just use $group = $home->defaultGroup(); if defaultGroup is a has_one relation
            if ($home && $home->defaultGroup()) {
                $member->Groups()->add($home->defaultGroup());
                $this->redirect('registeringThanks/');
            } else {
                $this->redirect('registrationFailed/');
            }
        }
        public function registeringThanks(SS_HTTPRequest $request) {
            // display the same page again, but overwrite the Title and Content
            return $this->customise(array(
                'Title' => 'Thank you!',
                'Content' => 'All sorts of spam mails are on there way to you',
            ));
        }
        public function registrationFailed(SS_HTTPRequest $request) {
            // display the same page again, but overwrite the Title and Content
            return $this->customise(array(
                'Title' => 'Great, ... you broke it!',
                'Content' => 'Sorry, we can\'t send you any spam because something went wrong',
            ));
        }
    }
    

    NOTE: I have not tested this code, I’ve just written this on top of my head, you might find spelling mistakes or other minor mistakes in it)
    (in this case you don’t need to redirect to home, the group stuff, the thankyou page and all work on every page this way)

    if you have any further questions, feel free to ask here or on http://irc.silverstripe.org/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a signup form with 3 fields: Username Email Password On most browsers
I have a form with three fields Name, Email Address & Password. now i
I have a long signup form and would like to hide a few fields
I have a basic newsletter signup form with an email field and two buttons
I have a user signup form, and I need to insert a function to
I have a simple signup form with the following jQuery validation code: $(document).ready(function(){ $(#registerForm).validate({
I have a div that is being used an a email newsletter signup form.
I have a sign-up form which prompts for the first name, last name, username,
The function below, as its name suggests, registers/records the data from signup form into
I have a signup button that switches screens for a signup form. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.