• Resolved MrAddy

    (@mraddy)


    I have followed the info on the website Temaplate Helper Class . And another on the 1.6 page, but i still am unable to get this working as I would like it, and its all do with groups.

    Here is a working example, does what I want, lists the fields in the record, but it lists all of them out of 5 groups:

    <div class="wrap <?php echo $this->wrap_class ?>">
    <?php while ( $this->have_groups() ) : $this->the_group(); ?>
        <table class="section" id="<?php echo Participants_Db::$css_prefix.$this->group->name ?>">
            <?php while ( $this->have_fields() ) : $this->the_field(); ?>
                <tr class="<?php echo Participants_Db::$css_prefix.$this->field->name.' '.$empty_class?>">
                    <td width="40%" class="<?php echo $this->field->name.' '.$empty_class?>"><?php $this->field->print_label() ?></td>
                    <td width="40%" name="<?php echo $this->field->name ?>" class="<?php echo $this->field->name.'_input'?>"><?php $this->field->print_value(); ?></td>
                    <td width="20%">
                        <div class="<?php echo $this->field->name?>_edit">
                            <a id="edit" href="" name="<?php echo $this->field->name?>">Edit</a>
                        </div>
                        <div class="edit <?php echo $this->field->name?>_save">
                            <a  id="save" href="" name="<?php echo $this->field->name?>">Save</a>
                        </div>
                    </td>
                </tr>
            <?php endwhile; // end of the fields loop ?>
        </table>
    <?php endwhile; // end of the groups loop ?>
    </div>

    Works a treat.

    However, I need it to only use one group to view. So I have been playing with:

    $record = new PDb_Template($this);
    $record = $record->groups['main'];
    var_dump($record);

    $record gives me the group, but I cannot use the methods with it, for example:

    echo $record->fields->print_value('city');

    gives me either NULL, or fails to load the page.

    Any advice on this please ?

    Thanks Addy

Viewing 1 replies (of 1 total)
  • Thread Starter MrAddy

    (@mraddy)

    I have managed to do this part of the function by using the following code:

    <div class="wrap <?php echo $this->wrap_class ?>">
    
            <?php while ($this->have_groups()) : $this->the_group(); ?>
                <h2><?php //echo $this->group->name ?></h2>
    
                <table class="section" id="<?php echo Participants_Db::$css_prefix . $this->group->name ?>">
    
                    <?php while ($this->have_fields()) : $this->the_field() ?>
    
                        <?php if($this->group->name == "main") { ?>
                        <tr class="<?php echo Participants_Db::$css_prefix . $this->field->name . ' ' . $empty_class ?>">
    
                            <td width="40%"
                                class="<?php echo $this->field->name . ' ' . $empty_class ?>"><?php $this->field->print_label() ?></td>
    
                            <td width="40%" name="<?php echo $this->field->name ?>"
                                class="<?php echo $this->field->name . '_input' ?>"><?php $this->field->print_value() ?></td>
    
                            <td width="20%">
                                <div class="<?php echo $this->field->name ?>_edit">
                                    <a id="edit" href="" name="<?php echo $this->field->name ?>">Edit</a>
                                </div>
                                <div class="edit <?php echo $this->field->name ?>_save">
                                    <a type="submit" id="save" href="" name="<?php echo $this->field->name ?>">Save</a>
                                </div>
                            </td>
                        </tr>
                    <?php } ?>
                    <?php endwhile; // end of the fields loop ?>
                </table>
            <?php endwhile; // end of the groups loop ?>
    
    </div>

    If you also notice, I have added the ability to update a field without having to refresh the page using jQuery. Here is the function for this:

    jQuery(document).on('click', '#edit', function (e) {
            e.preventDefault();
            var box = "." + jQuery(this).attr('name') + "_input";
    
            console.log(box);
            jQuery(box).attr('contenteditable', true);
    
            jQuery("div." + jQuery(this).attr('name') + "_save").removeClass("edit");
            jQuery("div." + jQuery(this).attr('name') + "_edit").addClass("edit");
            jQuery(box).focus();
        });
    
        jQuery(document).on('click', '#save', function (e) {
            e.preventDefault();
            var box = "." + jQuery(this).attr('name') + "_input";
            var newVal = jQuery(box).text();
            var column = jQuery(box).attr('name');
            jQuery(box).attr('contenteditable', false);
            jQuery("div." + jQuery(this).attr('name') + "_edit").removeClass("edit");
            jQuery("div." + jQuery(this).attr('name') + "_save").addClass("edit");
            //console.log('VALUE: ' + newVal + ' - And Column to update: ' + column);
            jQuery.ajax({
                url: '/wp-content/themes/dt-the7/functions/sql_functions.php',
                type : 'POST',
                data : 'action=pdb_update&pdb=<?php echo $record->id ?>&col=' + jQuery(this).attr('name') + '&val=' + newVal,
                success: function(res) {
    
                   // console.log(res);
                }
            })
        });

    This Ajax call is made to another file which handles the saving of the field. This is what is looks like:

    include ('../../../../wp-load.php');
    global $wpdb;
    
    $action = $_POST['action'];
    
    switch ($action) {
    
        case "pdb_update":
            $wpdb->update("xwdi_participants_database", array($_POST['col'] => $_POST['val']), array("id" => $_POST['pdb']));
            echo $res;
            break;
    }

    Hope it helps others ??

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Participation Database] pdb_single custom template group issue’ is closed to new replies.