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.

Form Questions /

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

Change the status of a user


Go to End
Reply


5 Posts   749 Views

Avatar
cumquat

Community Member, 200 Posts

18 January 2013 at 12:15am

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

Avatar
cumquat

Community Member, 200 Posts

18 January 2013 at 12:47am

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();
		}
	
	}

Avatar
cumquat

Community Member, 200 Posts

18 January 2013 at 3:52am

Edited: 18/01/2013 9:33pm

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
Avatar
copernican

Community Member, 189 Posts

22 January 2013 at 6:34am

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.

Avatar
cumquat

Community Member, 200 Posts

23 January 2013 at 10:19pm

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