シナリオ: WordPressをNinjaフォームと組み合わせて使用しており、PHP/SQLで選択リストを作成したいと思います。NinjaフォームPopulate SQL/PHPで選択
可能な場合は、jQueryを使用せずにPHPとSQLを使用して入力する、選択フィールドを持つ単純なフォームを作成しました。
NinjaフォームAPIと他のリソースを調べたところ、私の答えは見つかりませんでした。
これらのコードスニペットを使用して、テキストフィールドとテキストエリアフィールドには入力できますが、選択フィールドは入力できません。
詳細情報が必要な場合は投稿できます。
And this one that works with custom post types
// filter
add_filter('ninja_forms_render_default_value', 'my_change_nf_default_value', 10, 3);
function my_change_nf_default_value($default_value, $field_type, $field_settings, $default_option, $field_id) {
if($fh = fopen("/var/www/virtual/wp-content/themes/xxxx/error.log", "a+")){ fwrite ($fh,$field_type."\n"); fclose($fh); }
if('textarea' == $field_type){
$default_value = 'fooBARRRRRRRRR';
$options = 'foo';
}
return $default_value;
}
apply_filters(‘ninja_forms_render_default_value’, $default_value, $field_type, $field_settings, $field_id, $default_option);
//Function
function cpt_prepopulate_forms($options, $settings) {
global $post;
if($fh = fopen("/var/www/virtual/wp-content/themes/xxxx/error.log", "a+")){ fwrite ($fh,var_export($data,true)); fclose($fh); }
if($settings['id'] == 152) // change to your field ID
{
$args = array(
'post_type' => 'cash', // Change to your Custom Post type
);
$query = new WP_Query($args);
if ($query->have_posts())
{
$options = array();
while ($query->have_posts())
{
$query->the_post();
$options[] = array(
'label' => get_the_title(),
'value' => $post->post_name,
'calc' => null,
'selected' => 0
);
}
}
wp_reset_postdata();
}
return $options;
$conn->close();
}
add_filter('ninja_forms_render_options','cpt_prepopulate_forms', 10, 2);
// end
これは動作しますが、私は唯一のテキストエリアまたはテキストフィールド/電子メールが、[いいえ]を選択/ドロップダウンを移入することができます。フォームは負荷時にNinjaformsによって生成されるので、カスタムPHPを<select></select>
の間に置くことはできません。