dkurth
Forum Replies Created
-
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldJustin..addendum..
I am not using JS to pull data from a database. Straight PHP on a single MySQL select search, where all the records in question are immediately available for insert into the fields. At this writing, fields are not empty and when I read them back, all the data is there…using the generic call.What is annoying is the multiple calls, which I am working on a way to “block” and only access the database once instead of nth number of times.
So tell me what I don’t know…all ears.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldJustin, That makes sense given the number of times the function is called. However, I see your code sample, yet it is not specific to which field it is being “called for” during each function call. Can you elaborate on the specific items that one could test for?
What I have observed is that if I push the data into the array, using test data, they display correctly. So I am unsure what I am to test for in a field-fill process.
In a pull from field, I would understand.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldJustin, I noticed that the callback being invoked for draw is called multiple times (every field plus 1). Why is that? Should it not be called only once, like the save call back??
You refer to in-line logic. What exactly do you test on and for? There is nothing but values. So far, I have seen all the fields return as expected, with the test data.
Can you elaborate what you were talking about?- This reply was modified 6 years ago by dkurth.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldOk, figured it all out. I still have some other questions on the select and checkbox field front, but here is how saving to your own table and data works. I write it here for others to not have to spend Sunday afternoon, in front of a computer!
Setting up the groups and the fields is well documented. I wont’ review that. But in terms of the callback, the online docs make it a bit over complicated. Here is the simplified version. 1.) You do not need to put the metagroup name in the function call or the callback type. Direct works just fine for storing fields and retrieving them. The only downside to this call, is that it is called repeatedly for the number of individual fields you have, plus 1. Why I do not know, but I put a flag in that is cleared by the redraw override and that solved the problem..although ungracefully.
add_filter('cmb2_override_meta_value', 'YourFunction', 10, 4); function mmd_get_methods_custom_data( $dont_override, $object_id, $args, $cmb2_field_object ) { // $dont_override = Just a feed back informational // $object_id = Same thing as the PostId // $args = Giant list of all the settings for the entire form data. Use results = print_r($args, true); and dump the results to a debuglog to see all the forms. // $cmb2_field_object = Name of your Group. Same as the Group Id // To set your data is a multidem array, where each record set (repeatable group) is // an index into the array. The total number of individual record sets you input, // will be the number of repeatable field groups that will appear on the screen. $Records = array(); $Record[0] = array( 'fieldname1' => 'Your String Value here', 'fieldname2' => 'Your String Value here', 'fieldname3' => 'Your String Value here', 'fieldname4'=> 'Your String Value here' ); $Record[1] = array( 'fieldname1' => 'Your String Value here2', 'fieldname2' => 'Your String Value here2', 'fieldname3' => 'Your String Value here2', 'fieldname4'=> 'Your String Value here2' ); $Data[] = $Record[0]; $Data[] = $Record[1]; return $Records; // <---------- this sends it to the system. } //----------------------------- // this function overides the system to storing it into your postmeta table // Again, not necessary to put your metabox group name in the filter call or function //------------------------------------------- add_filter('cmb2_override_meta_save', 'save_custom_data', 10, 2); add_filter('cmb2_override_meta_remove', 'save_custom_data', 10, 2); function save_custom_data($data, $values) { // the only field you care about is $values Here is the format // [type] => post // [id] => <Your Post ID> // [field_id] => <The Name of your Group > // [repeat] => 1 // [single] => 1 // [value] => Array // ( // [0] => Array // ( // [fieldname1] => 'The value in field1' // [fieldname2] => The value in field2 // ) // ) //You can access this as follows: $Data = $values['value']; $Field1Value = $Data[0]['fieldname1']; $Field1Value = $Data[1]['fieldname1']; }
I would put all the usual prevention around to make sure the field does exist, such as if (!array_key_exists(‘value’, $values)). But you get the idea. Simple, once you know the format of the system.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldI found this:
and it explains a method that appears to work and it does function, since I tried it.
There is also this post,
https://github.com/CMB2/CMB2/issues/728
that you responded to, a couple years back. Same technique.There is a but…..
Whether this method or the cmb2_override_meta_value method, the associated call back get called for the total number of fields in the group, plus 1.
Should it not be called only once since it is for the group. Or am I missing something?Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldNo problem. I can figure it out, with your help and give you some code for others, when it works. I do have the filters working and they appear to be called for every field. But when I attempt to see what field, via the $field parameter, it does not print out (using debug logs).
Can you tell me what the parameter definition are (or a link to where they are defined) AND what is the return data structure expected?
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldPerhaps this will help clarify my question:
In this sample, you are returning an array from the options table:
`add_filter( ‘cmb2_override_yourprefix_group_alt_data_demo_meta_value’, ‘yourprefix_group_alt_data_demo_override_meta_value’, 10, 4 );
function yourprefix_group_alt_data_demo_override_meta_value( $data, $object_id, $args, $field ) {
return get_option( ‘yourprefix_group_alt_data_demo’, array() );
}What the the format of the array returned by get_option? (second parameter) Does it match the field names of the form. It is like:
$Data = get_option( ‘yourprefix_group_alt_data_demo’, array());
$Data[‘field name]
or
$Data[record set][field name]What is the format of the array data you expect to be returned to the system?
‘
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldDid not take that you were angry. No worries.
I am just trying to understand the system, so that I can achieve the goal..and quickly. The forms are all up and display correctly. I just need to populate these fields with DB data and store the data from the fields. and then I will be done with this portion of the project.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldok… hummm, I think there is an assumption that is confusing me. If I understand what you just said, you don’t have a giant array of values in which I would access the field such as:
$Data = GetFieldValues()
$Data[Group Card Set][field id] =”;From my brains point of view, each of those records are stored somewhere and I can either access that data directly via an array using a field by field and record set by record set method
OR
You have a set of function calls (filters) that return one or more fields based on the field. With repeatable fields, which field valued value belongs to which Record set??
I am retrieving a entire table of records based on a list ID (custom post id). Each of the repeatable record set, a row of data is associated. This is repeated for all rows in the database as repeatable fields. How do I assign the right record to the right repeatable field location? Then the reverse, how do I access the data to store in the database.
Remember I am a C++ programmer, so you have to return or get something physical or an array or a variable to access something. Trying to figure out how this that works. Which is why I wanted the sample code. The code I saw, it was generic not showing the specifics of the repeatable fields.
Help me understand..
Forum: Plugins
In reply to: [CMB2] How to use this as a multi-column display. Any sample code?Will look those up.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldMichael – I did this technique successfully on my own using custom post with metaboxes, however, I did not have the ability to delete fields and add fields without hitting the database. Caused a lag and I did not have the time to rewrite what you have done quite brilliantly at. Using a cache system. Your system was more elegant in this regard. I am using cmb2 instead, but need to control the same functionality by using my own table for the plugin.
As a FYI, On a standard custom post metabox, you use a callback hook called ‘save_post’ to get an “Update” call and then you can do whatever you need to do with storage. It is always called with an UPDATE button …or any submit button for that matter.
add_action( ‘save_post’, ‘Your Function’);
I can not use the postmeta table, nor do I want the options table. These are membership records, not options or posts. Using postmeta as it has two dangers with that table. 1) if it becomes corrupted, all your data is gone. 2) I am adding thousands of records to a already heavily laid table. It is not performance effective for my application.
I just need to know how to hook into the filters properly..the examples are confusing to me. It is not how “I think”.
If you can give me a working sample showing, the proper use of the filter (I will admit I am not used to using filters..not my programming style), the retrieval from your cache and storage to your cache for effective display and retrieve of user entry, I will be good.
- This reply was modified 6 years ago by dkurth.
Forum: Plugins
In reply to: [CMB2] How to use this as a multi-column display. Any sample code?No, it is the backend in the admin section. I have tweaked your CSS values, so they are closer together, but it would be nice to save the space by having the abilty to display in two columns and not just one for a form entry metabox.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldGot it (and will do on the ticks).
Forgive the confusion….I have not used filters and hooks very much, as my background is a c++ programmer and not so much a php (but learning quickly).
Here is what I want to achieve:
I have a table with membership records. I want to fill the form with all the available records from that table. Then on “Add New Record”, it needs to be blank for the data entry.On clicking the “Update” button, I would then read ALL THE records, presently available and store them back into the data base,as a update and an insert for the new record.
Application
Now, if I am reading your documentation and sample correctly, I would be applying the filter to the group field, thus disabling all fields from being retrieved, within that group. (Please note, I am not using classes for this plugin, other than your own).function MetaBox() { $prefix = 'mmdlist'; $cmb = new_cmb2_box( array( 'id' => 'mmd_lists_ManualEntry', 'title' => __( 'Google Lists - Card Records : Manual Input', 'cmb2' ), 'object_types' => $prefix, // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, ) ); $group_field_id = $cmb->add_field( array( 'id' => $prefix . '_' . 'Records', 'type' => 'group', 'description' => __( 'Individual Directory Listings', 'cmb2' ), 'options' => array( 'group_title' => __( 'Record {#}', 'cmb2' ), 'add_button' => __( 'Add Another Record', 'cmb2' ), 'remove_button' => __( 'Remove Record', 'cmb2' ), 'sortable' => true, ), ) );' $data = apply_filters( 'cmb2_override_meta_value', 'cmb2_field_no_override_val', $group_field_id, array( 'id'=> $prefix . '_' . 'Records', 'type' => 'group' ), 'cmb2'); } add_filter( 'cmb2_override_meta_value', 'FormFilterOverride', 10, 4 );
function FormFilterOverride( $cmb2_field_no_override_val, $this_object_id, $a, $instance ) {
// make filter magic happen here…
return $cmb2_field_no_override_val;
};`or this is applied to each field, one by one? The confusing point for me. Filters are a bit of a gray area for me. I could understand if the array in the group or individual fields had a callback function that would be referenced. Such as
$cmb->add_group_field( $group_field_id, array( 'name' => $FieldDesc, 'id' => $prefix . $FieldId, 'type' => 'text', 'on_front' => false, 'save_field' => false, 'attributes' => array( 'required' => $Field['required'],) 'default' => 'Debbie', 'value_cb' => 'SetTextBox', <---------- THIS ) );
That does not seem to be the case. But apply filters and then add_filter call and to who and where is the data, seems to be a disconnect. Again, forgive the nativity on this point.
I need some working sample code showing the relationship between which fields are being overwritten and then how do I retrieve the field data so I can store to the the database.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldahgggg! I just want to place data in the fields and read them back (is it too much to ask!) . Hard coding data into default, does nothing either. But the boxes are looking good! I even tried this…no results.
add_action( ‘cmb2_admin_init’, ‘MetaBox’ );
function MetaBox()
{
$prefix = ‘mmdlist’;
$cmb = new_cmb2_box( array(
‘id’ => ‘mmd_lists_ManualEntry’,
‘title’ => __( ‘Google Lists – Card Records : Manual Input’, ‘cmb2’ ),
‘object_types’ => $prefix,
‘context’ => ‘normal’,
‘priority’ => ‘high’,
‘show_names’ => true,
) );$group_field_id = $cmb->add_field( array(
‘id’ => ‘ListRecords’,
‘type’ => ‘group’,
‘description’ => __( ‘Individual Directory Listings’, ‘cmb2’ ),
‘options’ => array(
‘group_title’ => __( ‘Record {#}’, ‘cmb2’ ),
‘add_button’ => __( ‘Add Another Record’, ‘cmb2’ ),
‘remove_button’ => __( ‘Remove Record’, ‘cmb2’ ),
‘sortable’ => true,
),
) );$cmb->add_group_field( $group_field_id, array(
‘name’ => $FieldDesc,
‘id’ => $prefix . $FieldId,
‘type’ => ‘text’,
‘on_front’ => false,
‘save_field’ => false,
‘attributes’ => array(
‘placeholder’ => $Field[‘PH’] ,
‘required’ => $Field[‘required’],
),
‘default’ => ‘Debbie’,
‘default_cb’ => ‘SetTextBox’,
) );
}function SetTextBox($args, $field)
{
DebugLog(‘SET FIELD VALUES’);
}- This reply was modified 6 years ago by dkurth.
Forum: Plugins
In reply to: [CMB2] Set Field values from database with add_group_fieldFound the call back feature, but it does not appear to do anything. Can you see what the problem is? Here is the code:
$group_field_id = $cmb->add_field( array(
‘id’ => ‘ListRecords’,
‘type’ => ‘group’,
‘description’ => __( ‘Individual Directory Listings’, ‘cmb2’ ),
‘options’ => array(
‘group_title’ => __( ‘Record {#}’, ‘cmb2’ ),
‘add_button’ => __( ‘Add Another Record’, ‘cmb2’ ),
‘remove_button’ => __( ‘Remove Record’, ‘cmb2’ ),
‘sortable’ => true,
),
) );$cmb->add_group_field( $group_field_id, array(
‘name’ => $FieldDesc,
‘id’ => $FieldId,
‘type’ => ‘text’,
‘before_row’ => ‘cmb2_before_row_if_2’,
) );function cmb2_before_row_if_2( $field_args, $field )
{
DebugLog(‘test function’);
}- This reply was modified 6 years ago by dkurth.