• 1) Let’s say I create a link to a page where I want to show some CDBT data.

    If I also pass the ID of the user in the GET of the link, as follows:

    https://www.mysite.com/some_page?id=1

    Is it possible to get the CDBT to show the record data (of a particular table) with the ID = 1 somehow?

    If we cannot (or should not) use GET – it possible to do this some other way?

    _______________________________________________________________

    2) And another question, imagine I have an “articles” table and a “suppliers” table.

    If I have this link

    https://www.mysite.com/article_page?supplier_id=1

    Is it possible to show a form to enter a new article for the supplier with ID = 1?

    Thank you.

    • This topic was modified 8 years, 2 months ago by levelupfx.
    • This topic was modified 8 years, 2 months ago by levelupfx.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author ka2

    (@ka2)

    Thank you for your inquiry.

    Yes, you can that both.

    1) How to customize view data by getting GET param.

    
    function my_filter_cdbt_shortcode_query_conditions( $conditions, $narrow_operator, $shortcode_name, $table ){
      $filtered_tables = [ 'my_table_name' ];
      $target_shortcodes = [ 'cdbt-view', 'cdbt-edit' ];
      $userid_column_name = 'my_user_id_column';
      if ( in_array( $shortcode_name, $target_shortcodes ) && in_array( $table, $filtered_tables ) && 'and' === $narrow_operator ) {
        $_current_user_id = isset( $_GET['ID'] ) ? intval( $_GET['ID'] ) : 0;
        if ( empty( $conditions ) ) {
          $conditions[$userid_column_name] = $_current_user_id;
        } else {
          $conditions = array_merge( $conditions, [ $userid_column_name => $_current_user_id ] );
        }
      }
      return $conditions;
    }
    add_filter( 'cdbt_shortcode_query_conditions', 'my_filter_cdbt_shortcode_query_conditions', 10, 4 );
    

    Please refer too this:

    https://www.ads-software.com/support/topic/how-to-show-only-current-user-records-from-db/

    2) How to customize entry form by getting GET param.

    – For example, fills with “supplier_id” as hidden field.

    
    function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
      $filtered_tables = [ 'articles' ];
      $target_shortcodes = [ 'cdbt-entry' ];
      if ( in_array( $shortcode_name, $target_shortcodes ) && in_array( $table, $filtered_tables ) ) {
        $_supplier_id = isset( $_GET['supplier_id'] ) ? intval( $_GET['supplier_id'] ) : 0;
        foreach ( $elements_options as $_i => $_option ) {
          if ( 'supplier_id' === $_option['elementName'] ) {
            $elements_options[$_i]['elementType'] = 'hidden';
            $elements_options[$_i]['defaultValue'] = $_supplier_id;
          }
        }
      }
      return $elements_options;
    }
    add_filter( 'cdbt_shortcode_custom_forms', 'my_shortcode_custom_forms', 10, 3 );
    

    Thank you,

    • This reply was modified 8 years, 2 months ago by ka2.
    Thread Starter levelupfx

    (@levelupfx)

    Hello ka2,

    thank you for your swift response.

    This filter function code should be added to the functions.php wordpress file, correct?

    I will try it out in a few hours and let you know how it goes.

    Thank you again!

    Regards

    • This reply was modified 8 years, 2 months ago by levelupfx. Reason: Added some more specific information to my question
    Plugin Author ka2

    (@ka2)

    Hi there,

    Yes, you understand. You should insert to the functions.php in your theme.

    Please try it,

    Thread Starter levelupfx

    (@levelupfx)

    Ka2,

    Let’s say I want the user to insert a product with a specific supplier ID.

    If I create a view shortcode to show, in some page, a table with suppliers like this:

    “Please select your supplier”

    ID | Supplier
    _______________
    1 | Toshiba
    2 | Sony

    Is it possible to change the table so that if the user clicks “Sony”, he is taken to the product registration page with Supplier ID = 2?

    Perhaps using some of the code in my first post?

    I think you show an example like this in your japanese documentation, but Google Translate only helps until a certain point ??

    Thank you very much!

    • This reply was modified 8 years, 2 months ago by levelupfx.
    • This reply was modified 8 years, 2 months ago by levelupfx.
    • This reply was modified 8 years, 2 months ago by levelupfx.
    Plugin Author ka2

    (@ka2)

    Sorry for my late reply.

    For example, there is below permalink to link when clicked supplier of “Sony”.

    https://{your_registration_page_url}?id=2

    Then, it has placed a shortcode “cdbt-entry” in your registration page.

    Also, it’s as follows for filtered to render shortcode after retrieve param on url.

    
    function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
      $filtered_tables = [ 'your_table_name' ];
      $target_shortcodes = [ 'cdbt-entry' ];
      if ( in_array( $shortcode_name, $target_shortcodes ) && in_array( $table, $filtered_tables ) ) {
        $_supplier_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
        foreach ( $elements_options as $_i => $_option ) {
          if ( 'supplier_id' === $_option['elementName'] ) {
            $elements_options[$_i]['elementType'] = 'hidden';
            $elements_options[$_i]['defaultValue'] = $_supplier_id;
          }
        }
      }
      return $elements_options;
    }
    add_filter( 'cdbt_shortcode_custom_forms', 'my_shortcode_custom_forms', 10, 3 );
    

    Please try it.
    Thank you,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show/Insert data for a specific ID’ is closed to new replies.