Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Adding data to a form post

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

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

Page: 1
Go to End
Author Topic: 789 Views
  • Futureweb
    Avatar
    Community Member
    232 Posts

    Adding data to a form post Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Adding data to a form post Link to this post

    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)

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: Adding data to a form post Link to this post

    awesome- that works....

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