Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » pass variable to form from page i came from

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

Page: 1 2
Go to End
Author Topic: 1499 Views
  • Stefdv
    Avatar
    Community Member
    110 Posts

    pass variable to form from page i came from Link to this post

    Hello,

    I'm making a breeder site for dogs. Every dog shows a pedigree, from that pedigree a user can link to all the dogs in the pedigree showing that dogs pedigree etc.

    When i don't have information on a dogs father or mother, but the user does have this information they can fill in a form to add that dog to the database. Right now this is working (MultiStepForm) but the user has to choose from a dropdownfield for which dog it is the father or mother.

    I need a way to pass the name of the dog they came from to the form so they don't have to choose the dog manually. ( they came from the detailed page of a certain dog when they opened the form through a link).

    any thoughts on this. ( i hope my explanation makes sence)

    EDIT

    By going through my code again, i tink i have to refrase my question.

    In fact i need to pass a variable from within a control loop to my form.

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: pass variable to form from page i came from Link to this post

    You still building that thing ;-)

    Try "pre-loading" the control information in php and then you'll have the variable available for afterwards...

    http://www.silverstripe.org/template-questions/show/13619#post290481

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: pass variable to form from page i came from Link to this post

    LOL

    Swaiba, keep running into you

    Yes, still building that thing. Since reactions from my 'testpanel' are verry good, i'm still enjoying it. An other aspect of the wole thing is that i have a 'goal' to get to know more and more about Silverstripe and php.

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: pass variable to form from page i came from Link to this post

    Swaiba,

    I was in fact trying something like pre-loading ( i noticed when i folowed your link ). The problem is that i don't know how to get to my function ( that is in my Dog DataObject) from within my Multistepform.

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: pass variable to form from page i came from Link to this post

    the session?

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: pass variable to form from page i came from Link to this post

    You mean a session variable ???

    Again i realise how little i know ;)

    I post some code from my template to hopefully clarify some things

    <!-- START WITH FATHER -->

    <% if MyDad %>
    <% control MyDad %>

       <!-- GRANDFATHER -->

          <% if MyDad %>
             <% control MyDad %>
           <td rowspan="2">&nbsp;</td>
                <td rowspan="2"><a href="$Link">$PedigreeName</td>

          <!-- GREATGRANDFATHER -->

             <% if MyDad %>
                <% control MyDad %>
                      <td >&nbsp;</td>
                    <td><a href="$Link">$PedigreeName</a></td>
                <tr>
                <% end_control %>
              <% end_if %>

          <!-- GREATGRANDMOTHER -->

    <% if MyMom %>
                <% control MyMom %>
                <td>&nbsp;</td>
                   <td><a href="$Link">$PedigreeName</a></td>
                <% end_control %>
             <% end_if %>
          
    <% end_control %>

    <% else %> <!-- there is no GrandFather -->
                <td rowspan="2">&nbsp;</td>
             <td rowspan="2">If you have information on $PedigreeName's Father click <a href="$PedigreeLink">here</a></td>
    <% end_if %>

    The $PedigreeLink is a function in my Dog DO where i return the link to my form. I need to take the $PedigreeName with me to the form.

    I trully hope you're willing to clarify this a bit ( well, a lot to be honest )

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: pass variable to form from page i came from Link to this post

    ok, wherever you process the return values place something into the session (you can create whatever structure you like and serialize it) then when you need the data read it back from the session.

    http://api.silverstripe.org/trunk/sapphire/control/Session.html

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: pass variable to form from page i came from Link to this post

    Okay Swaiba,

    So in my function getMyDad i put

    Session::set('ChildDog', $PedigreeName);

    I am in the control MyDad and i need the PedigreeName of the currentdog.

    Then in my Dog DO i make another function

    function getChild()
       {
          $child = Session::get('ChildDog');
          return $child;
       }

    Then in my form i want to get that PedigreeName stored in session ChildDog ?
    So ( just an example !)

    <% control Child %>
          <h3>You are about to fill in the data for $child 's Father</h3>
    <% end_control %>

    where do i go wrong ?

    1499 Views
Page: 1 2
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.