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.

All other Modules /

Discuss all other Modules here.

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

User Forms - Pre Populate the form based on POST/GET


Go to End


5 Posts   2146 Views

Avatar
swaiba

Forum Moderator, 1899 Posts

3 August 2011 at 2:15am

Hi,

I've got a need to populate a UserForm with values if a user clicks through to the form with a particular route. For example a contact us form (with name, email and comments), if you go directly to it then the form is empty and you need to fill everything. However if you go via the page "I'm interested in Silverstripe" and click the "contact us and find out more" then the form field "comments" is pre-populated with "I'm interested in Silverstripe".

Can anyone give me some pointers for this?

I've tried setting the session with the form data, but this hasn't worked yet and if it did it doesn't account for changing the form.
The only other solution would be to have some custom onload javascript to fill the fields with required values.

Barry

Avatar
swaiba

Forum Moderator, 1899 Posts

9 August 2011 at 10:38pm

*bump*

any help pointers are much appreciated :)

Avatar
Willr

Forum Moderator, 5523 Posts

10 August 2011 at 7:48pm

UserDefinedForm's Form method allows you to define an updateForm() hook (https://github.com/silverstripe/silverstripe-userforms/blob/master/code/UserDefinedForm.php#L354) add a decorator to that that loads the data from $_GET..

public function updateForm($form) {
$form->loadDataFrom($_GET);
}

Avatar
swaiba

Forum Moderator, 1899 Posts

10 August 2011 at 11:34pm

Thank you Will, much appreciated!

Avatar
Arno

Community Member, 2 Posts

14 April 2012 at 12:51am

Would you be able to give me an example? As I really need this function, but I do not understand it at this moment.

I am putting this function in "class OfferteAanvragenPage extends UserDefinedForm {".