• Hi,

    Having a problem, I have to show the logged in user that this much data you have stored in our database. I am using the SQL generated by this plugin which is displayed after the table in plugin’s database view.
    but when I added ANDSubmitted Login= '$username' in in WHERE clause, SQL is showing error ” #1054 – Unknown column ‘Submitted Login’ in ‘where clause’ “.

    please help me.
    PS: $username is defined as:

    global $current_user;
    get_currentuserinfo();
    $username = $current_user->user_login;

    https://www.ads-software.com/extend/plugins/contact-form-7-to-database-extension/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    If I understand right, you have copied the SQL shown on the admin page and are trying to use a modified version of that in a SQL statement.

    In that case, you would want
    AND field_name = 'Submitted Login' and field_value = 'username'
    but you will need to put in the actual username of the user in the SQL statement. Using a “$username” won’t just work.

    Thread Starter ekansh005

    (@ekansh005)

    how can i actually put the actual username every time. i want it to be dynamically generated.

    Plugin Author Michael Simpson

    (@msimpson)

    if (is_user_logged_in()) {
                     $current_user = wp_get_current_user(); // WP_User object
                     $username = $current_user->user_login; // String user name
                }

    Almost the same, but I need to use shortcode. Retrieve data where the Name equals the page user. the plugin variable is:

    $user_data = pg_user_logged();
    echo $user_data->username;

    How do I get that into [cfdb-table] to only retrieve for the current user.

    Thanks,

    Plugin Author Michael Simpson

    (@msimpson)

    I am using the ‘PrivateContent’ plugin. So the user I need has to be their user variable and not the Global user variable listed on that page. I am rusty at programming so I was hoping to use the shortcode.

    $user_data = pg_user_logged();
    echo $user_data->username;

    I do use this code to display the page login name, and it works. I just need to get this into the [cfdb-table] filter.

    Thanks

    Where do you put the code you recommended to ekansh005?

    I just need to insert the pg_user_logged() variable.

    SS

    Plugin Author Michael Simpson

    (@msimpson)

    I’m not familiar with PrivateContent plugin. If pg_user_logged() is not the same as wp_get_current_user() they you have a problem.

    If a user is logged in when he submits a form, then a “Submitted Login” field is generated by this plugin and captured as the value of wp_get_current_user()->user_login. If the user comes back, is logged in, and views a page with a short code, then the short code can be set to display only entries where “Submitted Login” = the user’s current wp_get_current_user()->user_login.

    If the user has some other ID given by pg_user_logged(), the plugin is not aware of it. Which means it is not captured with the form submission and therefore you can not filter on it. (You would have to add some code to inject this field when the form is submitted…you would do this via this method)

    If I’ve missed the point here, I can try to answer in principle. Give you have some value given by pg_user_logged(), and that value is captured in the DB as some field XXX, then you can filter on that but it will require some extra work. You would need to Create Your Own Short Code, and programmatically add in the value as a filter. Something like this:

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
    // Need to "require" whatever file gives you the pg_user_logged() function
    $exp = new CFDBFormIterator();
    $user = pg_user_logged();
    $user_field = "XXX"; // whatever field captured the value of pg_user_logged() during submission
    $atts['filter'] = $user_field . '=' . $user;
    $exp->export($atts['form'], $atts);
    while ($row = $exp->nextRow()) {
     // Output for each row here
    }
    Plugin Author Michael Simpson

    (@msimpson)

    Come to thing of it, you could potentially delegate to another short code:

    // Need to "require" whatever file gives you the pg_user_logged() function
    $user = pg_user_logged();
    $user_field = "XXX"; // whatever field captured the value of pg_user_logged() during submission
    $atts['filter'] = $user_field . '=' . $user;
    
    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBShortcodeTable.php');
    $shortcode = new CFDBShortcodeTable;
    $shortcode->handleShortcode($atts);

    //Still working on this:
    Thanks,

    Looks like you understand the issue, but it still not return data (no errors either)

    MY SHORTCODE:

    require_once(ABSPATH . ‘wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php’);
    // Need to “require” whatever file gives you the pg_user_logged() function
    $exp = new CFDBFormIterator();
    $exp->export($atts[‘form’], $atts);
    // Load page user into $userloadvar – this will echo
    $user_data = pg_user_logged();
    $userloadvar = $user_data->username;
    $user_field = “Name”;
    $atts[‘filter’] = $user_field . ‘=’ . $userloadvar;
    while ($row = $exp->nextRow())
    {
    echo ‘<h2>’ . $row[‘Name’] . ‘</h2>’;
    echo ‘<p>’ . $row[‘LongGoals’] . ‘</p>’;
    }

    SHORTCODE [cfdb-table] returns these fields with rows of data

    Submitted, Name, LongGoals, MIDGoals, ShortGoals, Submitted Login, Submitted From

    It does not appear that I am reading the database.

    SS

    Plugin Author Michael Simpson

    (@msimpson)

    I suggesting putting in log statements in your code to see what is going on. See the debug section of this page

    Very little progress.

    Was able to create function to submit page-name into table field.

    Now I should be able to retreive dynamicly (using same page_user) data. Is the code you provided (see above) correct. Still no table data and no errors???

    FYI, Table has 4 rows – 2 with identical names in ‘Name’ column.

    Got it finally. Thanks.
    SS

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: Contact Form 7 to Database Extension] How to display data of a logged in user only’ is closed to new replies.