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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Adding data to a form post


Go to End


3 Posts   1192 Views

Avatar
JonShutt

Community Member, 244 Posts

1 February 2011 at 8:55pm

Hello,

I have a form, which allows users to create a 'listing' on the site. The form submits ok, and saves into my table, but I want to attached the member user id to the form post, and store it with the listing, so i know which listings below to which user

this is the function i'm using to take the data and save it

function doListingForm($data, $form) {
$submission = new ListingSubmission();
$form->saveInto($submission);
$submission->write();
Director::redirectBack();
}

but I have no idea where to add the extra details.

I've tried "$data[UserID] = $CurrentMember.ID" but this didn't work, and a few other ideas failed too..

any help appreciated

Avatar
swaiba

Forum Moderator, 1899 Posts

1 February 2011 at 10:18pm

how about...

   function doListingForm($data, $form) { 
      $submission = new ListingSubmission(); 
      $form->saveInto($submission); 
      $submission->MemberID = Member::currentUserID();
      $submission->write();       
      Director::redirectBack(); 
   }

(untested and assuming ListingSubmission $has_one Member)

Avatar
JonShutt

Community Member, 244 Posts

1 February 2011 at 11:12pm

awesome- that works....