0

I need to create a contest forms where the fields are based on values in several custom fields. The form layout is to be somewhat static, except from the contest questions (labels) and the type of those fields. Here's the basic layout.

[Label - <Subject>] -based on custom field
[Input - hidden]

[Label - <Question 1>] -based on custom field values
[Input - textfield OR x3 radiobuttons] -based on custom field values

[Label - <Question 2>] -based on custom field values
[Input - textfield OR x3 radiobuttons] -based on custom field values

[Label - <Question 3>] -based on custom field values
[Input - textfield OR x3 radiobuttons] -based on custom field values

[Label - Name]
[Input - textfield]

[Label - Email]
[Input - textfield]

Tried something like this with Jetpack forms. But can't get it to work. The output is correct, but the form wont submit.

Suggestions on how to solve this? I've looked at a couple of different form plugins (GF, CF7), but have not found anything that can do this.

0

Our solution to this was to use Formidable Pro and the following setup.

//**************************************************
// 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;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.