Php 使用ExpressionEngine safecracker隐藏表单字段
我已经在我的网站前端创建了一个表单,允许注册成员在不需要访问管理CP的情况下发布帖子,但是我想在输出中隐藏一个特定的表单元素 我们想要隐藏的元素是一个勾选框,它允许显示只有管理员才能看到的项目。这是否可以使用自动表单输出?我使用了以下安全破解代码:Php 使用ExpressionEngine safecracker隐藏表单字段,php,expressionengine,safecracker,Php,Expressionengine,Safecracker,我已经在我的网站前端创建了一个表单,允许注册成员在不需要访问管理CP的情况下发布帖子,但是我想在输出中隐藏一个特定的表单元素 我们想要隐藏的元素是一个勾选框,它允许显示只有管理员才能看到的项目。这是否可以使用自动表单输出?我使用了以下安全破解代码: {global_errors}{error}{/global_errors} <label for="title">Title</label> <input type="text" name="title" id="t
{global_errors}{error}{/global_errors}
<label for="title">Title</label>
<input type="text" name="title" id="title" value="{title}" size="50" maxlength="100" onkeyup="liveUrlTitle();">
{status_menu}
<label for="status">Status</label>
<select name="status" id="status">
{select_options}
</select>
{/status_menu}
{custom_fields}
<p><label for="{field_name}">{if required}* {/if}{field_label}</label>
{field_instructions}
{formatting_buttons}
{if error}
<span class="error">{error}</span>
{/if}
{if textarea}
<textarea id="{field_name}" name="{field_name}" dir="{text_direction}" rows="{rows}">{field_data}</textarea>
{/if}
{if text}
<input type="text" dir="{text_direction}" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50">
{/if}
{if select}
<select id="{field_name}" name="{field_name}">
{options}<option value="{option_value}"{selected}>{option_name}</option>{/options}
</select>
{/if}
{if date}
<input type="text" id="{field_name}" name="{field_name}" value="{field_data}" size="50">
{/if}
{if checkbox}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{/if}
{if radio}
{options}
<label class="checkbox">{option_value}
<input type="radio" id="{field_name}" name="{field_name}" value="{option_value}" {checked}>
</label>
{/options}
{/if}
{if safecracker_file}
{display_field}
{/if}
{if relationship}
<select id="{field_name}" name="{field_name}">
{options}
<option value="{option_value}"{selected}>{option_name}</option>
{/options}
</select>
{/if}
{if multiselect}
<select id="{field_name}" name="{field_name}[]" multiple="multiple">
{options}
<option value="{option_value}"{selected}>{option_name}</option>
{/options}
</select>
{/if}
{if rte}
<textarea id="{field_name}" class="rte" name="{field_name}" dir="{text_direction}" rows="{rows}">{field_data}</textarea>
{/if}
</p>
{/custom_fields}
<input type="submit" name="submit" value="Submit">
{global\u errors}{error}{/global\u errors}
标题
{状态_菜单}
地位
{选择选项}
{/status_menu}
{自定义_字段}
{if required}*{/if}{field_label}
{field_指令}
{格式化按钮}
{if error}
{错误}
{/if}
{if textarea}
{field_data}
{/if}
{if text}
{/if}
{如果选择}
{options}{option_name}{/options}
{/if}
{如果日期}
{/if}
{如果复选框}
{options}
{option_value}
{/options}
{/if}
{中频无线电}
{options}
{option_value}
{/options}
{/if}
{if safecracker_file}
{display_field}
{/if}
{if关系}
{options}
{option_name}
{/options}
{/if}
{if multiselect}
{options}
{option_name}
{/options}
{/if}
{if-rte}
{field_data}
{/if}
{/custom_字段}
我不相信你能自动做到这一点
您可以将复选框包装为条件,检查管理员组(或多个组)的组ID:
{如果登录到组中{u id==1}
{/if}
或者,如果您有两个“管理员”组,则如下所示:
{if logged_in_group_id==1 | | logged_in_group_id==7}
{/if}
具体值取决于用户组(CP中的成员组)的ID号。我不相信这是可以自动完成的 您可以将复选框包装为条件,检查管理员组(或多个组)的组ID:
{如果登录到组中{u id==1}
{/if}
或者,如果您有两个“管理员”组,则如下所示:
{if logged_in_group_id==1 | | logged_in_group_id==7}
{/if}
具体值将取决于用户组的ID号(成员CP中的成员组)您可能会丢失
{custom_fields}
循环并硬编码所有字段
或者您可以扩展@unexplainedBacn的计划,并为字段名
以及成员组
添加一个测试,否则您将隐藏所有复选框
{if checkbox}
{if field_name == 'field_to_hide' && logged_in_group_id == 1}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{if:elseif field_name != 'field_to_hide'}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{/if}
{/if}
{if checkbox}
{if field_name=='field_to_hide'&&logged_in_group_id==1}
{options}
{option_value}
{/options}
{if:elseif field_name!=“field_to_hide”}
{options}
{option_value}
{/options}
{/if}
{/if}
您可能会丢失{custom_fields}
循环并硬编码所有字段
或者您可以扩展@unexplainedBacn的计划,并为字段名
以及成员组
添加一个测试,否则您将隐藏所有复选框
{if checkbox}
{if field_name == 'field_to_hide' && logged_in_group_id == 1}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{if:elseif field_name != 'field_to_hide'}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{/if}
{/if}
{if checkbox}
{if field_name=='field_to_hide'&&logged_in_group_id==1}
{options}
{option_value}
{/options}
{if:elseif field_name!=“field_to_hide”}
{options}
{option_value}
{/options}
{/if}
{/if}
{if checkbox}
{if field_name == 'field_to_hide' && logged_in_group_id == 1}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{if:elseif field_name != 'field_to_hide'}
{options}
<label class="checkbox">{option_value}
<input type="checkbox" id="{field_name}" name="{field_name}[]" value="{option_value}"{checked}>
</label>
{/options}
{/if}
{/if}