如何禁用某些重力形式ID的渲染HTML代码?
How to disable render HTML code of certain ID of gravity form?
我需要在我的 Gravity Form.
中禁用某个 id 的渲染 HTML
我已经找到了这样的东西:
add_filter( 'gform_field_content', function ( $field_content, $field, $value ) {
if ( $field->id == 2 ) {
if ( $field->is_entry_detail_edit() ) {
$value = esc_attr( $value );
$name = 'input_' . esc_attr( $field->id );
return "<input type='hidden' name='{$name}' value='{$value}'>";
} elseif ( $field->is_entry_detail() ) {
return '';
}
}
return $field_content;
}, 10, 3 );
那个会隐藏我的 id,但 HTML
仍然呈现。
我想我需要使用 filter => gform_pre_render
有人可以给我一些建议吗?
您提供的代码可防止 html 在条目详细信息部分输出。不是主窗体输出。
尝试这样的事情:
add_filter( 'gform_field_content', function ( $field_content, $field, $value ) {
if ( $field->id == 2 ) {
// Show the field in entry_detail and form editor
if ( GFCommon::is_entry_detail_view() || GFCommon::is_form_editor()) {
return $field_content;
}
// Otherwise don't show the field
return '';
}
// Show all other fields
return $field_content;
}, 10, 3 );
如果你想删除容器列表项标签也试试这个:
add_filter( 'gform_field_container', function ( $field_container, $field, $form, $css_class, $style, $field_content ) {
if ( GFCommon::is_entry_detail_view() || GFCommon::is_form_editor()) {
return $field_container;
}
if ( $field->id == 2 ) {
return '';
}
return $field_container;
}, 10, 3);
应该这样做:
function remove_field_by_id($objForm)
{
foreach ($objForm['fields'] as $iIndex => $objField) {
// if its the one you want to remove ...
if ($objField->id == 3) {
// replace that field object with an empty array
array_splice($objForm['fields'], $iIndex, 1, array());
}
}
return $objForm;
}
add_filter('gform_pre_render', 'remove_field_by_id');
我需要在我的 Gravity Form.
HTML
我已经找到了这样的东西:
add_filter( 'gform_field_content', function ( $field_content, $field, $value ) {
if ( $field->id == 2 ) {
if ( $field->is_entry_detail_edit() ) {
$value = esc_attr( $value );
$name = 'input_' . esc_attr( $field->id );
return "<input type='hidden' name='{$name}' value='{$value}'>";
} elseif ( $field->is_entry_detail() ) {
return '';
}
}
return $field_content;
}, 10, 3 );
那个会隐藏我的 id,但 HTML
仍然呈现。
我想我需要使用 filter => gform_pre_render
有人可以给我一些建议吗?
您提供的代码可防止 html 在条目详细信息部分输出。不是主窗体输出。
尝试这样的事情:
add_filter( 'gform_field_content', function ( $field_content, $field, $value ) {
if ( $field->id == 2 ) {
// Show the field in entry_detail and form editor
if ( GFCommon::is_entry_detail_view() || GFCommon::is_form_editor()) {
return $field_content;
}
// Otherwise don't show the field
return '';
}
// Show all other fields
return $field_content;
}, 10, 3 );
如果你想删除容器列表项标签也试试这个:
add_filter( 'gform_field_container', function ( $field_container, $field, $form, $css_class, $style, $field_content ) {
if ( GFCommon::is_entry_detail_view() || GFCommon::is_form_editor()) {
return $field_container;
}
if ( $field->id == 2 ) {
return '';
}
return $field_container;
}, 10, 3);
应该这样做:
function remove_field_by_id($objForm)
{
foreach ($objForm['fields'] as $iIndex => $objField) {
// if its the one you want to remove ...
if ($objField->id == 3) {
// replace that field object with an empty array
array_splice($objForm['fields'], $iIndex, 1, array());
}
}
return $objForm;
}
add_filter('gform_pre_render', 'remove_field_by_id');