WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form DB
[Plugin: Contact Form 7 to Database Extension] How to display data of a logged in user only (14 posts)

  1. ekansh005
    Member
    Posted 1 year ago #

    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;

    http://wordpress.org/extend/plugins/contact-form-7-to-database-extension/

  2. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. ekansh005
    Member
    Posted 1 year ago #

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

  4. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    if (is_user_logged_in()) {
                     $current_user = wp_get_current_user(); // WP_User object
                     $username = $current_user->user_login; // String user name
                }
  5. SSpearjr
    Member
    Posted 1 year ago #

    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,

  6. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

  7. SSpearjr
    Member
    Posted 1 year ago #

    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

  8. SSpearjr
    Member
    Posted 1 year ago #

    Where do you put the code you recommended to ekansh005?

    I just need to insert the pg_user_logged() variable.

    SS

  9. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    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
    }
  10. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

    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);
  11. SSpearjr
    Member
    Posted 1 year ago #

    //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

  12. Michael Simpson
    Member
    Plugin Author

    Posted 1 year ago #

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

  13. SSpearjr
    Member
    Posted 1 year ago #

    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.

  14. SSpearjr
    Member
    Posted 1 year ago #

    Got it finally. Thanks.
    SS

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic