Jump to content

Set checkbox unchecked via API


heldercervantes
 Share

Recommended Posts

Hi guys,

I'm kinda stuck here. How do you set an InputfieldCheckbox to unchecked via API?

I've tried setting it to false, 0, '' and nothing seems to work.

Shouldn't be relevant, but I'm using this to control whether a user's password was auto or manually generated. So when a password recovery is requested, I'm doing:

$user->setOutputFormatting(false);
$user->pass = $randomGeneratedPassword;
$user->passwordSet = false;
$user->save();

passwordSet is the name of my field. This is generating and saving the random password correctly, but that checkbox stays checked.

  • Like 1
Link to comment
Share on other sites

I'm positive it's going through this code. The password is being changed and also after this it sends an email to the user with the new password and that's working too.

I'm thinking it may be some weirdness related to the page being a user. If I don't get there, I'll just use another kind of field.

Link to comment
Share on other sites

Once again I make an ass of myself :)

For starters, I was testing the frontend part on the server and looking at the CMS locally. It was all downhill from there.

This to say of course setting it to false unchecks the box. Sorry for wasting your time.

Now excuse me while I go reflect on life.

  • Like 3
  • Haha 1
Link to comment
Share on other sites

  • 4 years later...

When working with Checkboxes ("Type: Page Reference - Input field type: Checkboxes - with Page field value type: Multiple pages PageArray" fields, that is), this works:

$rs = $pages->find('template=foo, parent=/bar/');
	foreach ($rs as $p) {
	$p->of(false);
	$p->myCheckboxes = null; // Unset all values first
	$p->myCheckboxes = 'baz'; // Then set the active checkbox with name (or, use Page ID)
	$p->save();
}

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...