0

登録メンバーが管理CPにアクセスしなくても投稿できるように、サイトのフロントエンドにフォームを作成しましたが、特定のフォーム要素を出力から非表示にします。

非表示にしたい要素は、管理者だけが表示できるアイテムを表示できるようにするチェックボックスです。自動化されたフォーム出力を使用してこれは可能ですか?私は次のセーフクラッカーコードを使用しました:

{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">
4

2 に答える 2

3

ループが失われ、{custom_fields}すべてのフィールドがハードコーディングされる可能性があります。

または、@unexplainedBacn の計画を拡張してfield_name、同様にテストを追加することもできます。member_groupそうしないと、すべてのチェックボックスが非表示になります。

{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}
于 2012-09-17T18:39:08.053 に答える
0

それが自動的にできることだとは思いません。

チェックボックスを条件付きでラップして、管理者グループ (またはグループ) のグループ ID を確認できます。

{if logged_in_group_id == 1} 
  <input type="checkbox" [...] />
{/if}

または、2 つの「管理者」グループがある場合は、次のようになります。

{if logged_in_group_id == 1 || logged_in_group_id == 7} 
  <input type="checkbox" [...] />
{/if}

具体的な値は、ユーザー グループの ID 番号によって異なります ( CP の[メンバー] > [メンバー グループ])。

于 2012-09-17T14:14:54.390 に答える