• 虹色ミツバチ
  • freoカスタマイズメモ、テンプレート・プラグイン配布/officeTIPS
検索プラグイン
虹色ミツバチ

> Entry >freo>freoTips>テンプレート系TIPS> エントリー登録画面でオプション入力項目を個別に表示する方法

【freo】【freoTips】【テンプレート系TIPS】エントリー登録画面でオプション入力項目を個別に表示する方法

エントリー登録画面では、[管理画面]→[設定管理]→[オプション管理]で登録した、「エントリーに使用するオプション」または「全てに利用するオプション」として設定されたオプションの入力項目が一覧表示されます。
オプション入力項目を個別に表示する方法は以下のとおりです。

例1:foreachの条件分岐を利用する

オプション入力項目は、エントリー登録画面のテンプレートで一覧表示されています。
一覧表示するために、foreach文を利用してオプション入力項目を繰り返して表示しています。
foreach文にif文を加筆して条件分岐でオプションを指定する方法は以下のとおりです。

  1. [freo/templates/internals/admin/entry_form]の25行目~65行目を以下のように編集する。
                        <!--{foreach from=$options|smarty:nodefaults item='option'}-->
                        <!--{if $option.id == '表示したいオプションID'}-->
                        <dt>{$option.name}<!--{if $option.required == 'yes'}--> <abbr class="attention" title="入力必須">*</abbr><!--{/if}--></dt>
                            <!--{if $option.type == 'text'}-->
                            <dd><input type="text" name="entry_associate[option][{$option.id}]" size="50" value="{if $freo.query.id or $freo.query.session or $smarty.server.REQUEST_METHOD == 'POST'}{$input.entry_associate.option[$option.id]}{else}{$option.text}{/if}" /></dd>
                            <!--{elseif $option.type == 'textarea'}-->
                            <dd><textarea name="entry_associate[option][{$option.id}]" cols="50" rows="5">{if $freo.query.id or $freo.query.session or $smarty.server.REQUEST_METHOD == 'POST'}{$input.entry_associate.option[$option.id]}{else}{$option.text}{/if}</textarea></dd>
                            <!--{elseif $option.type == 'select'}-->
                            <dd>
                                <select name="entry_associate[option][{$option.id}]">
                                    <option value="">選択してください</option>
                                    <!--{foreach from=$option_texts[$option.id]|smarty:nodefaults item='option_text'}-->
                                    <option value="{$option_text}"{if $input.entry_associate.option[$option.id] == $option_text} selected="selected"{/if} >{$option_text}</option>
                                    <!--{/foreach}-->
                                </select>
                            </dd>
                            <!--{elseif $option.type == 'radio'}-->
                            <dd>
                                <!--{if $option.required == 'no'}-->
                                <input type="radio" name="entry_associate[option][{$option.id}]" id="label_option_{$option.id}" value=""{if !$input.entry_associate.option[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">選択なし</label>
                                <!--{/if}-->
                                <!--{foreach from=$option_texts[$option.id]|smarty:nodefaults item='option_text' name='loop'}-->
                                <input type="radio" name="entry_associate[option][{$option.id}]" id="label_option_{$option.id}_{$smarty.foreach.loop.index}" value="{$option_text}"{if $input.entry_associate.option[$option.id] == $option_text} checked="checked"{/if} /> <label for="label_option_{$option.id}_{$smarty.foreach.loop.index}">{$option_text}</label>
                                <!--{/foreach}-->
                            </dd>
                            <!--{elseif $option.type == 'checkbox'}-->
                            <dd>
                                <!--{assign var='options' value=$input.entry_associate.option[$option.id]|explode:"\n"}-->
                                <!--{foreach from=$option_texts[$option.id]|smarty:nodefaults item='option_text' name='loop'}-->
                                <input type="checkbox" name="entry_associate[option][{$option.id}][]" id="label_option_{$option.id}_{$smarty.foreach.loop.index}" value="{$option_text}"{if $option_text|in_array:$options} checked="checked"{/if} /> <label for="label_option_{$option.id}_{$smarty.foreach.loop.index}">{$option_text}</label>
                                <!--{/foreach}-->
                            </dd>
                            <!--{elseif $option.type == 'file'}-->
                            <dd>
                                <input type="file" name="entry_associate[option][{$option.id}]" size="30" />
                                <!--{if $input.entry_associate.option[$option.id]}-->
                                    <input type="checkbox" name="entry_associate[option_remove][{$option.id}]" id="label_option_{$option.id}" value="{$input.entry_associate.option[$option.id]}"{if $input.entry_associate.option_remove[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">{$input.entry_associate.option[$option.id]}を削除</label>
                                    <input type="hidden" name="entry_associate[option][{$option.id}]" value="{$input.entry_associate.option[$option.id]}" />
                                <!--{/if}-->
                            </dd>
                            <!--{/if}-->
                        <!--{/if}-->
                        <!--{/foreach}-->
    
  2. [freo/templates/internals/admin/entry_form]を上書きしてアップロードする。

上記ソースは、ソース内2行目「<!--{if $option.id == '表示したいオプションID'}-->」及び42行目「<!--{/if}-->」を加筆し、表示するオプションIDを指定しています。

表示するオプションIDを複数設定したい場合は、

                    <!--{foreach from=$options|smarty:nodefaults item='option'}-->
                    <!--{if $option.id == '表示したいオプションID' or $option.id == '表示したいオプションID2'}-->
                    ~中略~
                    <!--{/if}-->
                    <!--{/foreach}-->

上記のようにif文にオプションIDを加筆していけばよいでしょう。

例2:オプションIDを直接指定する

オプション入力項目は、エントリー登録画面のテンプレートで一覧表示されています。
一覧表示している箇所とは別に、オプションIDを指定した入力項目を設定したい場合は、下記のとおりに編集してください。

  1. [freo/templates/internals/admin/entry_form]のオプション入力項目を表示したい箇所
                        <dt>{$options.表示したいオプションID.name}<!--{if $options.表示したいオプションID.required == 'yes'}--> <abbr class="attention" title="入力必須">*</abbr><!--{/if}--></dt>
                            <!--{if $options.表示したいオプションID.type == 'text'}-->
                            <dd><input type="text" name="entry_associate[option][{$options.表示したいオプションID.id}]" size="50" value="{if $freo.query.id or $freo.query.session or $smarty.server.REQUEST_METHOD == 'POST'}{$input.entry_associate.option[$options.表示したいオプションID.id]}{else}{$options.表示したいオプションID.text}{/if}" /></dd>
                            <!--{elseif $options.表示したいオプションID.type == 'textarea'}-->
                            <dd><textarea name="entry_associate[option][{$options.表示したいオプションID.id}]" cols="50" rows="5">{if $freo.query.id or $freo.query.session or $smarty.server.REQUEST_METHOD == 'POST'}{$input.entry_associate.option[$options.表示したいオプションID.id]}{else}{$options.表示したいオプションID.text}{/if}</textarea></dd>
                            <!--{elseif $options.表示したいオプションID.type == 'select'}-->
                            <dd>
                                <select name="entry_associate[option][{$options.表示したいオプションID.id}]">
                                    <option value="">選択してください</option>
                                    <!--{foreach from=$option_texts[$options.表示したいオプションID.id]|smarty:nodefaults item='option_text'}-->
                                    <option value="{$option_text}"{if $input.entry_associate.option[$options.表示したいオプションID.id] == $option_text} selected="selected"{/if} >{$option_text}</option>
                                    <!--{/foreach}-->
                                </select>
                            </dd>
                            <!--{elseif $options.表示したいオプションID.type == 'radio'}-->
                            <dd>
                                <!--{if $options.表示したいオプションID.required == 'no'}-->
                                <input type="radio" name="entry_associate[option][{$options.表示したいオプションID.id}]" id="label_option_{$options.表示したいオプションID.id}" value=""{if !$input.entry_associate.option[$options.表示したいオプションID.id]} checked="checked"{/if} /> <label for="label_option_{$options.表示したいオプションID.id}">選択なし</label>
                                <!--{/if}-->
                                <!--{foreach from=$option_texts[$options.表示したいオプションID.id]|smarty:nodefaults item='option_text' name='loop'}-->
                                <input type="radio" name="entry_associate[option][{$options.表示したいオプションID.id}]" id="label_option_{$options.表示したいオプションID.id}_{$smarty.foreach.loop.index}" value="{$option_text}"{if $input.entry_associate.option[$options.表示したいオプションID.id] == $option_text} checked="checked"{/if} /> <label for="label_option_{$options.表示したいオプションID.id}_{$smarty.foreach.loop.index}">{$option_text}</label>
                                <!--{/foreach}-->
                            </dd>
                            <!--{elseif $options.表示したいオプションID.type == 'checkbox'}-->
                            <dd>
                                <!--{assign var='options' value=$input.entry_associate.option[$options.表示したいオプションID.id]|explode:"\n"}-->
                                <!--{foreach from=$option_texts[$options.表示したいオプションID.id]|smarty:nodefaults item='option_text' name='loop'}-->
                                <input type="checkbox" name="entry_associate[option][{$options.表示したいオプションID.id}][]" id="label_option_{$options.表示したいオプションID.id}_{$smarty.foreach.loop.index}" value="{$option_text}"{if $option_text|in_array:$options} checked="checked"{/if} /> <label for="label_option_{$options.表示したいオプションID.id}_{$smarty.foreach.loop.index}">{$option_text}</label>
                                <!--{/foreach}-->
                            </dd>
                            <!--{elseif $options.表示したいオプションID.type == 'file'}-->
                            <dd>
                                <input type="file" name="entry_associate[option][{$options.表示したいオプションID.id}]" size="30" />
                                <!--{if $input.entry_associate.option[$options.表示したいオプションID.id]}-->
                                    <input type="checkbox" name="entry_associate[option_remove][{$options.表示したいオプションID.id}]" id="label_option_{$options.表示したいオプションID.id}" value="{$input.entry_associate.option[$options.表示したいオプションID.id]}"{if $input.entry_associate.option_remove[$options.表示したいオプションID.id]} checked="checked"{/if} /> <label for="label_option_{$options.表示したいオプションID.id}">{$input.entry_associate.option[$options.表示したいオプションID.id]}を削除</label>
                                    <input type="hidden" name="entry_associate[option][{$options.表示したいオプションID.id}]" value="{$input.entry_associate.option[$options.表示したいオプションID.id]}" />
                                <!--{/if}-->
                            </dd>
                            <!--{/if}-->
    
    のソースを加筆する。
  2. [freo/templates/internals/admin/entry_form]を上書きしてアップロードする。

表示するオプションをIDを複数設定したい場合は、上記のソースを書き換えて更に加筆すればOKです。

例3:オプション入力項目一覧で特定のオプションのみ表示しない

  1. [freo/templates/internals/admin/entry_form]の25行目~65行目を以下のように編集する。
                        <!--{foreach from=$options|smarty:nodefaults item='option'}-->
                        <!--{if $option.id != '表示したくないオプションID'}-->
                        <dt>{$option.name}<!--{if $option.required == 'yes'}--> <abbr class="attention" title="入力必須">*</abbr><!--{/if}--></dt>
                            <!--{if $option.type == 'text'}-->
                            <dd><input type="text" name="entry_associate[option][{$option.id}]" size="50" value="{if $freo.query.id or $freo.query.session or $smarty.server.REQUEST_METHOD == 'POST'}{$input.entry_associate.option[$option.id]}{else}{$option.text}{/if}" /></dd>
                            <!--{elseif $option.type == 'textarea'}-->
                            <dd><textarea name="entry_associate[option][{$option.id}]" cols="50" rows="5">{if $freo.query.id or $freo.query.session or $smarty.server.REQUEST_METHOD == 'POST'}{$input.entry_associate.option[$option.id]}{else}{$option.text}{/if}</textarea></dd>
                            <!--{elseif $option.type == 'select'}-->
                            <dd>
                                <select name="entry_associate[option][{$option.id}]">
                                    <option value="">選択してください</option>
                                    <!--{foreach from=$option_texts[$option.id]|smarty:nodefaults item='option_text'}-->
                                    <option value="{$option_text}"{if $input.entry_associate.option[$option.id] == $option_text} selected="selected"{/if} >{$option_text}</option>
                                    <!--{/foreach}-->
                                </select>
                            </dd>
                            <!--{elseif $option.type == 'radio'}-->
                            <dd>
                                <!--{if $option.required == 'no'}-->
                                <input type="radio" name="entry_associate[option][{$option.id}]" id="label_option_{$option.id}" value=""{if !$input.entry_associate.option[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">選択なし</label>
                                <!--{/if}-->
                                <!--{foreach from=$option_texts[$option.id]|smarty:nodefaults item='option_text' name='loop'}-->
                                <input type="radio" name="entry_associate[option][{$option.id}]" id="label_option_{$option.id}_{$smarty.foreach.loop.index}" value="{$option_text}"{if $input.entry_associate.option[$option.id] == $option_text} checked="checked"{/if} /> <label for="label_option_{$option.id}_{$smarty.foreach.loop.index}">{$option_text}</label>
                                <!--{/foreach}-->
                            </dd>
                            <!--{elseif $option.type == 'checkbox'}-->
                            <dd>
                                <!--{assign var='options' value=$input.entry_associate.option[$option.id]|explode:"\n"}-->
                                <!--{foreach from=$option_texts[$option.id]|smarty:nodefaults item='option_text' name='loop'}-->
                                <input type="checkbox" name="entry_associate[option][{$option.id}][]" id="label_option_{$option.id}_{$smarty.foreach.loop.index}" value="{$option_text}"{if $option_text|in_array:$options} checked="checked"{/if} /> <label for="label_option_{$option.id}_{$smarty.foreach.loop.index}">{$option_text}</label>
                                <!--{/foreach}-->
                            </dd>
                            <!--{elseif $option.type == 'file'}-->
                            <dd>
                                <input type="file" name="entry_associate[option][{$option.id}]" size="30" />
                                <!--{if $input.entry_associate.option[$option.id]}-->
                                    <input type="checkbox" name="entry_associate[option_remove][{$option.id}]" id="label_option_{$option.id}" value="{$input.entry_associate.option[$option.id]}"{if $input.entry_associate.option_remove[$option.id]} checked="checked"{/if} /> <label for="label_option_{$option.id}">{$input.entry_associate.option[$option.id]}を削除</label>
                                    <input type="hidden" name="entry_associate[option][{$option.id}]" value="{$input.entry_associate.option[$option.id]}" />
                                <!--{/if}-->
                            </dd>
                            <!--{/if}-->
                        <!--{/if}-->
                        <!--{/foreach}-->
    
  2. [freo/templates/internals/admin/entry_form]を上書きしてアップロードする。

表示したくないオプションIDが複数ある場合は、

                    <!--{foreach from=$options|smarty:nodefaults item='option'}-->
                    <!--{if $option.id != '表示したくないオプションID' or $option.id != '表示したくないオプションID2'}-->

                    ~~中略~~

                    <!--{/if}-->
                    <!--{/foreach}-->

のようにif文にオプションIDを加筆していけばOKです。

ページ移動

関連記事

ユーティリティ

Twitter

ページ上部へ