Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Jetpack has a bug and can't properly handle do_shortcode plugins.trac.wordpress.org/ticket/1762 –  EyesX Jun 20 '13 at 12:59
add comment

1 Answer

up vote 0 down vote accepted

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;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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