Jump to:

1970 Posts in 1272 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » [Solved] Custom forms 2.4.2

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

Page: 1
Go to End
Author Topic: 773 Views
  • Mo
    Avatar
    Community Member
    485 Posts

    [Solved] Custom forms 2.4.2 Link to this post

    Hi All,

    Has anyone had problems creating custom forms in 2.4.2? I have a very simple form that is created in a method in my page controller. For some reason thought it doesn't seem to be calling the method specified in the action. It just seems to re-direct to the form's url with the forms method name tacked on the end?

    Any ideas?

    Mo

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: [Solved] Custom forms 2.4.2 Link to this post

    Have you added the action method to the allowed actions array?

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: [Solved] Custom forms 2.4.2 Link to this post

    Yep.

    I have actually tried downgrading to 2.4.1 and am getting the same problem. I don't think there is anything wrong with my code :s.

    Here is my Page_Controller:

    class Page_Controller extends ContentController {
    public static $allowed_actions = array(
    'guessForm'
    );

    public function init() {
    parent::init();
    ...
    }

    public function guessForm() {
    $fields = new FieldSet(
    new TextField('Content','Any idea yet? Have a guess'),
    new HiddenField('OwnerID', 'ID', $this->getPlayer()->ID)
    );

    $actions = new FieldSet(new FormAction("doSubmitGuess","Submit"));

    $validator = new RequiredFields();
    $validator->set_javascript_validation_handler('none');

    return new Form($this,"guessForm",$fields,$actions,$validator);
    }

    public function doSubmitGuess($data,$form) {
    $guess = new Guess();
    $form->saveInto($guess);
    $guess->write();

    Director::redirectBack();
    return;
    }
    }

    I had already got the allowed actions entry. I have also written a unit test to sets saving of $guess and its associations, which pass. It just seems the form does not process the submit action .

    I have also tried altering "Director::redirectBack();" with no luck.

    Any ideas? This has me stumped. I don't think I am making some NOOB mistake, but I might be...

    Mo

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: [Solved] Custom forms 2.4.2 Link to this post

    Ok, this was just being a Noob!!

    I had a method in the controller that was re-directing if the incorrect action was supplied. Obviously this re-direct happens before the POST data is processed.

    All fixed now.

    Mo

    773 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.