Jump to content

Set checkbox to checked in admin


Manaus
 Share

Recommended Posts

Hello, I have a page with multiple checkboxes, each enables or disables (or should) a Page value in a template... the Page value represents $users linked to that specific page.

I have this code:

$d = $input->post->recipients;  // array of values, such as rec[1010]=>true, rec[1024]=>true
$c->of(false);  // $c is the page
foreach ($d as $dest) {
  $c->recipients->set($dest, true);  // recipients is the Page field in the template
}
$c->save();
$c->of(true);

Still I have it not working,

Thanks for any suggestion..!

Link to comment
Share on other sites

I don't understand the code example well enough. But I'm thinking maybe you are intending to do something like this?

$c->recipients = $input->post->recipients; 

While that would work, it would be better to do some thorough validation, like this:

$c->recipients->removeAll();
foreach($input->post->recipients as $id) {
  $recipient = $pages->get((int) $id); 
  if($recipient->id && $recipient->template->name == 'recipient') {
    $c->recipients->add($recipient); 
  }
} 
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...