Skip to:
Content
Pages
Categories
Search
Top
Bottom

Nested Fields – conditonal fields – Possible solution


  • blu3shad0w
    Participant

    @blu3shad0w

    Hi

    Like many people I’m after having nested fields…

    I thought that this might be the solution http://wordpress.org/plugins/fields-framework/

    Since it had a way of putting fields into groups..and well nesting those groups.

    Would it be possible to take the code and integrate it into buddypress or http://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/

    The code in question from what I can work out from the fields-framework plugin is…

    Classes.php

    if(!class_exists(‘FF_Field_Group’)) {
    class FF_Field_Group extends FF_Field {
    protected $fields = array();

    public function set_saved_value($saved_value) {
    $saved_value = parent::set_saved_value($saved_value);

    if($this->repeatable != true) {
    foreach($this->fields as $field) {
    $set_saved_value = !ff_empty($saved_value) && is_array($saved_value) && array_key_exists($field->name, $saved_value) ? $saved_value[$field->name] : null;

    $saved_value[$field->name] = $field->set_saved_value($set_saved_value);
    }
    }
    elseif(!ff_empty($saved_value) && is_array($saved_value)) {
    foreach($saved_value as &$value) {
    foreach($this->fields as $field) {
    $set_saved_value = !ff_empty($value) && is_array($value) && array_key_exists($field->name, $value) ? $value[$field->name] : null;

    if(ff_empty($value) || is_array($value)) {
    $value[$field->name] = $field->set_saved_value($set_saved_value);
    }
    }
    }
    }

    return $saved_value;
    }

    public function html() {
    $field_group_id = $this->id;

    $field_group_name = $this->name;

    foreach($this->fields as $field) {
    $original_field_name = $field->name;

    $original_field_id = $field->id;

    $field->name = “{$field_group_name}[{$original_field_name}]”;

    $field->id = “{$field_group_id}-{$original_field_id}”;

    $value = is_array($this->value) && array_key_exists($original_field_name, $this->value) ? $this->value[$original_field_name] : null;

    $field->set_saved_value($value);

    $field->container();

    $field->name = $original_field_name;

    $field->id = $original_field_id;
    }
    }

    public function add_field($field) {
    $this->fields[] = $field;
    }
    }
    }

    Functions

    if(!function_exists(‘ff_add_field_to_field_group’)) {
    function ff_add_field_to_field_group($field_group_uid, $field_uid) {
    if(empty(FF_Registry::$fields[$field_group_uid])) {
    ff_throw_exception(__(‘Invalid Field Group UID’, ‘fields-framework’));
    }

    if(empty(FF_Registry::$fields[$field_uid])) {
    ff_throw_exception(__(‘Invalid Field UID’, ‘fields-framework’));
    }

    FF_Registry::$fields[$field_group_uid]->add_field(FF_Registry::$fields[$field_uid]);
    }
    }

    It also features in builder but not able to work out the coding….

    Idea of putting fields into groups and then nesting them, might be the way forward..

    If that could then be combined with the conditional fields plugin, might then be onto a winner…

    Sorry, I know zero about php coding, but I hope I might point someone onto the way…..

  • The topic ‘Nested Fields – conditonal fields – Possible solution’ is closed to new replies.
Skip to toolbar