Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

pass variable to form from page i came from


Go to End


13 Posts   2991 Views

Avatar
Stefdv

Community Member, 110 Posts

31 March 2011 at 10:47pm

Edited: 31/03/2011 11:16pm

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

31 March 2011 at 11:57pm

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

Avatar
Stefdv

Community Member, 110 Posts

1 April 2011 at 12:01am

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.

Avatar
Stefdv

Community Member, 110 Posts

1 April 2011 at 12:13am

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

1 April 2011 at 12:19am

the session?

Avatar
Stefdv

Community Member, 110 Posts

1 April 2011 at 12:33am

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 :( )

Avatar
swaiba

Forum Moderator, 1899 Posts

1 April 2011 at 12:59am

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

Avatar
Stefdv

Community Member, 110 Posts

1 April 2011 at 1:51am

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 ?

Go to Top