smartyのフォームselectでループしながら本日の日付にselectedする方法。
PHPで行こう!
に関連する記事です。
これは自分への覚書です。
問い合わせフォームなどで本日の日付をselectedするサンプルです。
phpファイル
$year = date('Y');
$month = date('n');
$day = date('j');
$smarty->assign('year', $year);
$smarty->assign('month', $month);
$smarty->assign('day', $day);
テンプレートファイル
<select name="year">
<option value="">選択</option>
<{section name="sel_year" start=2011 loop=2020}>
<option value="<{$smarty.section.sel_year.index|escape}>"<{if $year == $smarty.section.sel_year.index}> selected="selected"<{/if}>><{$smarty.section.sel_year.index|escape}></option>
<{/section}>
</select>年
<select name="month">
<option value="">選択</option>
<{section name="sel_month" start=1 loop=13}>
<option value="<{$smarty.section.sel_month.index|escape}>"<{if $month == $smarty.section.sel_month.index}> selected="selected"<{/if}>><{$smarty.section.sel_month.index|escape}></option>
<{/section}>
</select>月
<select name="day">
<option value="">選択</option>
<{section name="sel_day" start=1 loop=32}>
<option value="<{$smarty.section.sel_day.index|escape}>"<{if $day == $smarty.section.sel_day.index}> selected="selected"<{/if}>><{$smarty.section.sel_day.index|escape}></option>
<{/section}>
</select>日
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ホームページ制作・システム構築・DB設計
●ユタデザイン
●住所:〒135-0062
東京都江東区東雲2-7-5-2105
ユタデザイン
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+