Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Input::post('var_perms'); | Form | $_POST
  • Hi, everyone

    I need do this:

    Input::post('name', isset($entity) ? $entity->name : '')

    but for this field checkboxes['.$item['role']->id.'][]

    Where if value is not setting, then default value will are an empty array

    Thanks

  • HarroHarro
    Accepted Answer
    If you do it like this, you need to keep track of what checkboxes where defined.

    Assuming this is about an ORM relation assignment, and the checkbox id's represent the id' of the child objects, you need to do something like this:

    // get the parent with all it's children
    $parent = Model_Parent::find($key, array('related' => 'children'));

    // get the list of checked child id's
    $checked = Input::post('checkboxes', array());

    // remove all children currently assigned but not checked anymore
    foreach ($parent->children as $id => $child)
    {
        if ( ! in_array($id, $checked))
        {
            unset($parent->children[$id]);
        }
    }

    // add children checked now but not assigned yet
    foreach ($checked as $id)
    {
        if ( ! array_key_exists($id, $parent->children))
        {
            $parent->children[] = Model_Child::find($id);
        }
    }

    // update
    $parent->save();

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion