Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Change the status of a user

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

Page: 1
Go to End
Author Topic: 463 Views
  • cumquat
    Avatar
    Community Member
    191 Posts

    Change the status of a user Link to this post

    Ok i apologise first, i'm having a really really bad week and my brain is fried. This maybe a simple request but i just cant see it any-more.
    I have a table of users displayed on the front end, just lists their name the company name and their status.
    The status can be either 1 or 2 and on the same row as their details i want to put a button that if their status is 1 when it's clicked it changes the status to 2 if it's clicked again it changes it to 1.

    That's it and I cant think of the best way to do it.... is this gonna be a form or is there another way of doing this, which is best?

    Hope you can help

    Mick

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Change the status of a user Link to this post

    Ok i have moved forward, maybe...

    I believe this is the code i need but for the life of me i cant work out how to call this function from a button click.

    public function Activate() {
       $memberid = $this->owner->ID;
       $member = Member::get()->byID($memberid);
          if ($member) {
             $member->Status = "2";
             $member->write();
          }
       
       }

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Change the status of a user Link to this post

    Ok well 1 step forward 5 steps back...
    Below is a picture of what i'm trying to achieve.

    I'm using a form so i can call the Activate function and if i hard code the value of the hidden field to be a member ID it works.

    public function ActivateForm() {
        $fields = new FieldList(
                new HiddenField('ID' , 'aID', $ID )
             );
          $actions = new FieldList(
                new FormAction('Activate', 'Activate')
             );
             $form = new Form($this, 'ActivateForm', $fields, $actions);
             return $form;
       }
       
       public function Activate() {
          $theID = $_POST["ID"];
       
          $member = DataObject::get_by_id("Member", $theID);
          
          if ($member) {
             $member->Status = "2";
             $member->write();
          }
       Controller::curr()->redirectBack();
       }


    The trouble is as this form is called within a control loop i have to use the $Up.ActivateForm to display the form but this therefore that puts the form outside of the Member loop.
    How do i get the member ID value i can pass it the ActivateForm function?

    Mick

    Attached Files
  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Change the status of a user Link to this post

    I can't remember if this works or not with SS3 new template system but you could try passing in the member id as an argument.

    <% loop Member %>
    $Up.ActivateForm($ID)
    <% end_loop %>

    and in your ActivateForm() function

    public function ActivateForm($memberID){
    if($memberID){
    $ID = $memberID;
    }
    ..... rest of your code
    }

    Not sure if that will work though.

    A better solution would be to make this ajax driven. It would create a much friendlier user experience but does add some complexity for you. http://ss2doc-v2.ernie.silverstripe.com/old/recipes:ajax_basics.

  • cumquat
    Avatar
    Community Member
    191 Posts

    Re: Change the status of a user Link to this post

    Hi ya,

    Thanks for the response, unfortunately the passing an argument didn't seem to work, the form just didn't show up. Will look at the ajax stuff although i don't really know too much about that.

    Thanks

    Mick

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