我们的解决方案是Formidable Pro 以及以下设置。
//**************************************************
// Generate the contest form
//**************************************************
// Determin if radio or not
add_filter(\'frm_field_type\', \'change_my_field_type\', 10, 2);
function change_my_field_type($type, $field){
global $post;
if($field->id == 8){
if (get_post_meta($post->ID, \'_cmeta_contest_q1_type\', true) !== \'field\') {
$type = \'radio\'; //change field to radio on multi-answer questions
} else {
$type = \'text\';
}
}
if($field->id == 9){
if (get_post_meta($post->ID, \'_cmeta_contest_q2_type\', true) !== \'field\') {
$type = \'radio\'; //change field to radio on multi-answer questions
} else {
$type = \'text\';
}
}
if($field->id == 10){
if (get_post_meta($post->ID, \'_cmeta_contest_q3_type\', true) !== \'field\') {
$type = \'radio\'; //change field to radio on multi-answer questions
} else {
$type = \'text\';
}
}
return $type;
}
// Get the questions and multi-answers
add_filter(\'frm_setup_new_fields_vars\', \'frm_set_checked\', 20, 2);
function frm_set_checked($values, $field){
global $post;
if($field->id == 8){
$values[\'name\'] = get_post_meta($post->ID, \'_cmeta_contest_q1\', true); // fetch question from given custom field
// Get data from custom field
$q1_radio = get_post_meta($post->ID, \'_cmeta_contest_q1_radio\');
if (get_post_meta($post->ID, \'_cmeta_contest_q1_type\', true) !== \'field\') {
$values[\'options\'] = array($q1_radio); // fetch question from given custom field
}
}
if($field->id == 9){
$values[\'name\'] = get_post_meta($post->ID, \'_cmeta_contest_q2\', true); // fetch question from given custom field
// Get data from custom field
$q2_radio = get_post_meta($post->ID, \'_cmeta_contest_q2_radio\');
if (get_post_meta($post->ID, \'_cmeta_contest_q2_type\', true) !== \'field\') {
$values[\'options\'] = array($q2_radio); // fetch question from given custom field
}
}
if($field->id == 10){
$values[\'name\'] = get_post_meta($post->ID, \'_cmeta_contest_q3\', true); // fetch question from given custom field
// Get data from custom field
$q3_radio_1 = get_post_meta($post->ID, \'_cmeta_contest_q3_radio_1\');
$q3_radio_2 = get_post_meta($post->ID, \'_cmeta_contest_q3_radio_2\');
$q3_radio_3 = get_post_meta($post->ID, \'_cmeta_contest_q3_radio_3\');
if (get_post_meta($post->ID, \'_cmeta_contest_q3_type\', true) !== \'field\') {
$values[\'options\'] = array($q3_radio_1,$q3_radio_2,$q3_radio_3); // fetch question from given custom field
}
}
return $values;
}