Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-03-15 04:11:13

conanfan
New Member
Registered: 2015-03-15
Posts: 2

Change Comment Fields

For page comments, I’ve changed the label for “Website” to “Location.” However, the database doesn’t accept any data after someone enters a space. Is there a way for me to fix this?

Thanks

Offline

#2 2015-03-15 09:12:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,171
Website GitHub Mastodon Twitter

Re: Change Comment Fields

Hi and welcome to txp

The reason it does not accept the data is because the field is checking for a valid url which is then used to link with the input in name field. I don’t think that there is a specific plugin which allows you to modify those fields but somebody here might come up with a solution for you if the system allows it.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2015-03-15 19:47:29

conanfan
New Member
Registered: 2015-03-15
Posts: 2

Re: Change Comment Fields

Is there a way to add a new field?

Offline

#4 2015-03-15 22:39:43

etc
Developer
Registered: 2010-11-11
Posts: 5,393
Website GitHub

Re: Change Comment Fields

conanfan wrote #289091:

Is there a way to add a new field?

Adding an input field to the comment_form is straightforward, but saving/retrieving it to/from db requires a bit of php (probably plugin-wrapped), I think.

Offline

#5 2015-03-16 04:11:27

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Change Comment Fields

etc wrote #289096:

Adding an input field to the comment_form is straightforward, but saving/retrieving it to/from db requires a bit of php (probably plugin-wrapped), I think.

The minimal amount of code would be something along the lines of:

register_callback('abc_comment_save', 'comment.saved');

/**
 * Saves the additional comment fields.
 */

function abc_comment_save($event, $step, $data)
{
    $columns = (array) @getThings('describe '.safe_pfx('txp_discuss')." 'abc\_comment\_%'");

    foreach ($columns as &$column) {
        $column = "`{$column}`='".doSlash(ps($column))."'";
    }

    safe_update('txp_discuss', implode(',', $columns), 'commentid = '.intval($data['commentid']));
}

/**
 * Renders additional comment data.
 */

function abc_comment_field($atts)
{
    global $thiscomment;

    extract(lAtts(array(
        'type' => '',
    ), $atts));

    assert_article();
    assert_comment();

    $column = 'abc_comment_' . $type;

    if (isset($thiscomment[$column])) {
        return txpspecialchars($thiscomment[$column]);
    }
}

/**
 * Renders comment input.
 */

function abc_comment_input($atts)
{
    extract(lAtts(array(
        'type'        => '',
        'title'       => '',
        'size'        => 0,
        'tabindex'    => 0,
        'id'          => null,
        'disabled'    => 0,
        'required'    => 0,
        'placeholder' => '',
    ), $atts));

    $name = 'abc_comment_' . txpspecialchars($type);

    if ($id === null) {
        $id = $name;
    }

    return fInput($name, ps($name), $name, $title, '', (int) $size, (int) $tabindex, $id, (bool) $disabled, (bool) $required, $placeholder);
}

Which includes a abc_comment_input tag for the form, abc_comment_field for the comment rendering and comment saving functionality. It’ll update and extract any field from the txp_discuss table prefixed with abc_comment_:

ALTER TABLE txp_discuss ADD abc_comment_location VARCHAR(255) NOT NULL DEFAULT ''

Offline

Board footer

Powered by FluxBB