我有这个代码:
add_filter('frm_get_default_value', 'form_fullname_value', 10, 2);
function form_fullname_value($name_value, $field){
//set array with all form fullname id's
$name_array = array(94, 83, 101, 185, 165, 114, 151);
//Set value for each fullname field
if(in_array($field->id, $name_array)){
//check if GET is set
if(isset( $_GET[ 'fullname' ] ))
{
$name_value = sanitize_text_field( $_GET[ 'fullname' ] );
//write cookie
setcookie("VNX[fullname]", $name_value);
}
else{ //see is cookie is set
if(isset($_COOKIE['VNX']['fullname']))
{
$name_value = $_COOKIE['VNX']['fullname'];
}
}
}
return $name_value;
}
这会以强大的形式预先填充表单字段。它工作正常,因为表格确实是预先填写的。但是 其中一个选项是单击一个复选框,该复选框显示相对于该选项要显示(设置为"显示无")的表单字段。当我使用上述函数时,字段不显示(保持隐藏)。如果我使用 wordpress 管理区域为字段提供一个值,它们就可以正常工作。我尝试通过此函数传递一个字符串以形成,但结果相同。以前有没有人遇到过这个问题,如果是的话,你是如何让它工作的。提前谢谢。John
对于任何寻求此修复程序的人,我使用了frm_setup_new_fields_vars函数:
add_filter('frm_setup_new_fields_vars', 'form_fullname_value', 10, 2);
function form_fullname_value($name_value, $field){
//set array with all form fullname id's
$name_array = array(94, 83, 101, 185, 165, 114, 151);
//Set value for each fullname field
if(in_array($field->id, $name_array)){
//check if GET is set
if(isset( $_GET[ 'fullname' ] ))
{
$name_value['value'] = sanitize_text_field( $_GET[ 'fullname' ] );
//write cookie
setcookie("VNX[fullname]", $name_value['value']);
}
else{ //see is cookie is set
if(isset($_COOKIE['VNX']['fullname']))
{
$name_value['value'] = $_COOKIE['VNX']['fullname'];
}
}
}
return $name_value;
}