Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Form - Missing argument 2 - function formAskAction($data, $form)

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

Page: 1
Go to End
Author Topic: 2334 Views
  • the_angry_angel
    Avatar
    Community Member
    1 Post

    Form - Missing argument 2 - function formAskAction($data, $form) Link to this post

    Here are the relevant parts that I'm having trouble with:

       function formAsk()
       {
          return new Form($this, 'formAskAction', new FieldSet(
             // List your fields here
             new HiddenField (
              'ProductName',
              'Product Name',
              $this->Title
             ),
             new HiddenField (
              'ProductId',
              'Product Id',
              $this->InternalProductId
             ),
             new LiteralField (
                'Explanation',
                '<p><b>Ask us a question about this product</b></p>
                <p>Please select the type of question you would like to ask and fill in the boxes below.</p>'
             ),
             new OptionsetField(
                'Who',
                'What type of question is this?',
                array(
                   self::FORM_WHO_SALES => 'Sales',
                   self::FORM_WHO_TECH => 'Technical Support'
                )
             ),
             new TextField('FirstName', 'First name'),
             new TextField('Surname'),
             new EmailField('Email'),
             new PhoneNumberField('Telephone', 'Telephone', 0),
             new TextareaField('Enquiry')
          ), new FieldSet(
             // List the action buttons here
             new FormAction('formAskAction', 'Submit')
          ), new RequiredFields(
             'Who', 'FirstName', 'Surname', 'Email', 'Enquiry'
          ));
       }

       function formAskAction($data, $form)
       {
          //Director::redirect($this->Link() . 'formAskDone?referrer=' . urlencode($data['Referrer']));
          $data = array('formAsk' => 'Thank you for your email! '.$this->form_who[intval($form->Who)]);
          return $this->customise($data);
       }

    When I post the form on the client front end I get

    [Warning] Missing argument 2 for Product_Controller::formAskAction(), called in /var/www/sapphire/core/control/Controller.php on line 162 and defined
    POST /new-product/formAskAction

    Now to my knowledge I've not updated my silverstripe version, and all that's changed from my working version was that I deleted the database on my development machine and then did a reinstall.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Form - Missing argument 2 - function formAskAction($data, $form) Link to this post

    Hi,

    simple fix, change this line:

    return new Form($this, 'formAskAction', new FieldSet( ...

    to:

    return new Form($this, 'formAsk', new FieldSet(

    The second argument of the Form constructor is the name of the method that returns it, not the action method.

    2334 Views
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.