Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Passing value from one form to another

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

Page: 1
Go to End
Author Topic: 1643 Views
  • phawley
    Avatar
    Community Member
    21 Posts

    Passing value from one form to another Link to this post

    Hello all. I'm migrating an inherited website over to Silverstripe and trying to implement all that is presently there. They have a one field form in the sidebar (Form A) which takes an email address and then on submit, a full form (FormB) is presented with the usual field (Name, Addy, Email Addy, etc.) and the email address is populated by what was filled out in the sidebar form.

    I have Form B working just fine (validating, saving, redirecting), but I am unable to figure out how exactly to pass the email address value from Form A to Form B.

    Form A is in the Page Controller and Form B is in its own Controller.

    I'm sure it's a simple this I'm just not getting head around, even after an exhaustive search of the forum archives.

    I greatly appreciate any help on this...thanks!
    Patrick

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: Passing value from one form to another Link to this post

    You could do it a number of ways, probably the easier (and cleanest) is to use the Session class to handle passing values between forms. So in the process function for form A you would have

    Session:set('PreviousFormsData', $data);

    Then on form B you would load the data from that session

    $form = new Form(.....

    if($data = Session::get('PreviousFormsData')) {
    $form->loadDataFrom($data);
    }

    return $form;

  • phawley
    Avatar
    Community Member
    21 Posts

    Re: Passing value from one form to another Link to this post

    Brilliant...thank you very much!

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