Search

bbPress Showcase » bbPress Themes

  1. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 46

    offline

    Hi _ck_

    I've added an extra field on post form using following code on theme's function.php

    if (defined('BACKPRESS_PATH')) {
    add_action( 'bb-post.php', 'custom_post_fields');
    } else {
    add_action( 'bb_post.php', 'custom_post_fields');
    }

    function custom_post_fields() {
    global $topic;
    $topic_id = $topic->topic_id;
    bb_update_topicmeta( $topic_id, 'link', $_POST['link'] );
    }

    function topic_meta($key, $topic_id = 0) {
    global $topic;
    $topic_id = $topic->topic_id;
    return bb_get_topicmeta($topic_id, $key);
    }

    then I added the following field on post-form.php


    <input name="link" type="text" id="link" size="50" maxlength="100" tabindex="34" required="required" />

    --------
    And it works fine. BUT

    Now, I want to allow users to edit this extra custom field on edit form too, if ever they want to edit after submission. what should I do? Can you please give me a solution?

    - Thanks!

    Posted 11 months ago #
  2. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 900

    offline

    bb_update_topicmeta( $topic_id, 'link', $_POST['link'] );

    That will get your site hacked, it's not sanitized and will allow mysql injection.

    Change it to

    bb_update_topicmeta( $topic_id, 'link', $bbdb->escape($_POST['link']) );

    To edit I guess put the same field on your edit form.

    <input name="link" type="text" id="link" size="50" maxlength="100" tabindex="34" required="required" value="<?php echo $topic->link; ?>" />
    Posted 11 months ago #
  3. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 46

    offline

    Thanks _ck_ but seems there is something wrong. Its' giving me some errors when I use bb_update_topicmeta( $topic_id, 'link', $bbdb->escape($_POST['link']) );

    Error: Fatal error: Call to a member function escape() on a non-object in D:\xampp\htdocs\forum\bb-templates\test\functions.php on line 24

    - Also It's not updating new data after editing. I'm using the following code for getting output in template.

    <?php echo topic_meta('link'); ?>

    Posted 11 months ago #
  4. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 900

    offline

    You'll need to do a global $bbdb; before it then if you get that error.

    Posted 11 months ago #
  5. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 46

    offline

    Thanks _ck_ error has gone. But extra custom field in post form is not updating after edit. I want to edit this field stuff like we edit title of the topic etc.

    Don't you think we need to find a hook for when a post is edited and run the same code we are already triggering when a post is first posted?

    Posted 11 months ago #
  6. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 900

    offline

    Yeah I have a few plugins that do that, there is a hook for new post and a hook for update post and then one that does both.

    You need to read the bbpress core, search for insert_post

    Posted 11 months ago #
  7. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 46

    offline

    _ck_ I can't do it. Please help me to do it. Give me code. Thanks

    Posted 11 months ago #
  8. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 900

    offline

    Try changing 'bb_post.php' to 'bb_insert_post'

    You also should check to make sure isset($_POST['link']) before trying to save it or you might get errors.

    If you are going to continue using software that is not made anymore, then you need to learn to read and understand the source code.

    Posted 11 months ago #
  9. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 46

    offline

    NO _ck_ I cannot figure out where to add isset($_POST['link']) as I was asking for complete code. I'm a noob, I can't work on your guess. I think, I should learn php first to ask next questions.

    - I'm losing hopes. I'm planing to leave bbPress. It's not helpful any-more.

    Posted 11 months ago #

RSS feed for this topic

Post a reply to “Allow users to edit custom form field”

You must log in to post.

keep _ck_ coding >> donate $5 <<     Theme Switcher:
23 users online from in the past 30 minutes. 8 bots 15 guests
6,240 views today 10,421 yesterday 89,978 peak. Most at once 51 today 80 yesterday 539 peak. Visited today: Jund186811, por7kco2, bel9uug9
2,408 posts in 414 topics over 78 months by 445 of 2,509 members. Latest: elena0429, dancome89, adyante