基于自定义域的表单域

时间:2013-05-19 作者:EyesX

我需要创建一个竞赛表单,其中字段基于多个自定义字段中的值。除了竞赛题(标签)和这些字段的类型之外,表单布局在某种程度上是静态的。这是基本布局。

[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]
已尝试something like this 具有Jetpack 表格。但无法使其工作。输出正确,但表单不会提交。

如何解决这个问题的建议?我查看了几个不同的表单插件(GF、CF7),但没有找到任何可以做到这一点的插件。

1 个回复
最合适的回答,由SO网友:EyesX 整理而成

我们的解决方案是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;
}

结束

相关推荐

Adding Custom Forms

我正在寻找创建一个婚礼网站,将有一个表单页面。其想法是,这是一个RSVP页面,访客将输入他们收到的邀请上的唯一字符串,并将他们带到另一个页面,该页面将包含信息(出席人数、客人数量等),然后将其存储在数据库中,这样我就有了一个完整的客人列表,可以用于以后的用途。我还不太熟悉Wordpress,那么有什么最简单的方法可以让页面包含表单,并且第二个输入页面不会显示在导航中?我应该能够编写php和形成html没有太多的麻烦,只是需要一个起点。