I’m using Cfdb-plugin and I’m trying to make select2 get values id, text and text2 from cfdb-database but only show id as option in select2. I need to populate hidden fields rstext and rstext2 with data-values text and text2 so that when the form is submitted, id, text and text2 will get saved to another table in their own columns (Cfdb will handle saving all fields at submit).
My table looks like this:
| id | text | text2 | rownumber |
-----------------------------------------------
| rs1 | rs1text | rs1text2 | 1 |
| rs2 | rs2text | rs2text2 | 2 |
| rs3 | rs3text | rs3text2 | 3 |
In my functions.php I have:
// cfdb shortcode
add_action('wpcf7_init', 'add_cf7_shortcode_select_rs');
function add_cf7_shortcode_select_rs() {
wpcf7_add_form_tag('select_rs', 'select_rs', true);
}
// cfdb-select
function select_rs($tag) {
$tag = new WPCF7_FormTag( $tag );
$form = 'RS-form';
$options = array();
$options['orderby'] = 'rownumber DESC';
require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
$exp = new CFDBFormIterator();
$exp->export($form, $options);
ob_start();
echo '<select name="select_rs[]" multiple="multiple" id="select_rs" class="rsselect js-example-basic-multiple wpcf7-form-control wpcf7-select">';
echo '<option value=""></option>';
while ($row = $exp->nextRow()) {
printf('<option data-id="%s" data-text="%s" data-text2="%s">%s</option>', $row['id'], $row['text'], $row['text2'], $row['id']);
}
echo '</select>';
$custom_tag=ob_get_contents();
ob_end_clean();
return sprintf('<span class="wpcf7-form-control-wrap %s">%s</span>', sanitize_html_class( $tag->name ), $custom_tag);
}
Create a Form Drop-Down with values from CFDB submissions
Also I would like to get select2-multiple selected and saved data with line breaks like this:
| id | text | text2 |
-----------------------------------
| rs1 | rs1text | rs1text2 |
| | moretext | |
| rs2 | rs2text | rs2text2 |
| | | moretext |
-----------------------------------
| rs3 | rs3text | rs3text2 |
| rs4 | rs4text | rs4text2 |
-----------------------------------
| rs2 | rs2text | rs2text2 |
How to do this with select2 in your plugin?
]]>[select* field-recipient include_blank "Label A | [email protected]" "Label B | [email protected]"]
By running add_filter( 'cfdb7_before_save_data', function ( array $form_data ): array { var_dump($form_data); } );
I get this output as recipient without return label value
["field-recipient"]=>
array(1) {
[0]=>
string(19) "[email protected]"
}
how can I access to label value?
]]>Does anyone know how to get that to add into my database?
I have my form on a Careers job post page and it’s important for me to know WHICH job someone is applying to. Im doing that by adding that [_post_title] special tag to the form. It just wont add to the Contact 7 Database.
Any help would be greatly appreciated!
]]>Cheers!
]]>What about the shortcodes?
They have the same syntax in both versions so where do they get the data?
From which table?
Thank you
]]>I get this error when I activate the plugin.
Warning: session_start(): Cannot find save handler ‘memcache’
What an be the cause of this? If I enable the latest CDMB plugin then this error dont appear.
Thanks
]]>