/ Published in: Smarty
it's an excerpt of a registration form with 3 pulldowns for birthday ( day, month, year )
check for empty vars and applying CSS classes to show error on "empty" fields.
there are probably better ways, but this works for me. any suggestions welcome.
check for empty vars and applying CSS classes to show error on "empty" fields.
there are probably better ways, but this works for me. any suggestions welcome.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
############ PHP PART ## build up 3 arrays with D M Y values for smarty ##days $bday_d[0]["name"] = ".."; $bday_d[0]["value"] = ""; for ($d=1;$d<=31;$d++) { $bday_d[$d]["name"] = $d; $bday_d[$d]["value"] = $d; } ##months $bday_m[0]["name"] = ".."; $bday_m[0]["value"] = ""; $bday_m[1]["name"] = "Januar"; $bday_m[1]["value"] = "01"; $bday_m[2]["name"] = "Februar"; $bday_m[2]["value"] = "02"; $bday_m[3]["name"] = "März"; $bday_m[3]["value"] = "03"; $bday_m[4]["name"] = "April"; $bday_m[4]["value"] = "04"; $bday_m[5]["name"] = "Mai"; $bday_m[5]["value"] = "05"; $bday_m[6]["name"] = "Juni"; $bday_m[6]["value"] = "06"; $bday_m[7]["name"] = "Juli"; $bday_m[7]["value"] = "07"; $bday_m[8]["name"] = "August"; $bday_m[8]["value"] = "08"; $bday_m[9]["name"] = "September"; $bday_m[9]["value"] = "09"; $bday_m[10]["name"] = "Oktober"; $bday_m[10]["value"] = "10"; $bday_m[11]["name"] = "November"; $bday_m[11]["value"] = "11"; $bday_m[12]["name"] = "Dezember"; $bday_m[12]["value"] = "12"; ##years $maxAge = "70"; $minAge = "14"; $thatYear = $thisYear - $maxAge; $bday_y[0]["name"] = ".."; $bday_y[0]["value"] = ""; $c=1; for ($y=$thisYear;$y>=$thatYear;$y--) { $bday_y[$c]["name"] = $y; $bday_y[$c]["value"] = $y; $c++; } $smarty->assign("bday_d", $bday_d ); $smarty->assign("bday_m", $bday_m ); $smarty->assign("bday_y", $bday_y ); ############ ERROR CHECKS $pg = $_POST["reg"]; if ($pg["birthday_day"] == "") { $errorcnt ++; $smarty->assign("error_birthday_day", 1); } if ($pg["birthday_month"] == "") { $errorcnt ++; $smarty->assign("error_birthday_month", 1); } if ($pg["birthday_year"] == "") { $errorcnt ++; $smarty->assign("error_birthday_year", 1); } ############ SMARTY CODE <select name="reg[birthday_day]" {if $error_birthday_day == 1}class="fielderror"{/if}> {section name=days loop=$bday_d} <option label="{$bday_d[days].name}" value="{$bday_d[days].value}" {if $post.birthday_day == $bday_d[days].value}SELECTED{/if}>{$bday_d[days].name}</option> {/section} </select> <select name="reg[birthday_month]" {if $error_birthday_month == 1}class="fielderror"{/if}> {section name=months loop=$bday_m} <option label="{$bday_m[months].name}" value="{$bday_m[months].value}" {if $post.birthday_month == $bday_m[months].value}SELECTED{/if}>{$bday_m[months].name}</option> {/section} </select> <select name="reg[birthday_year]" {if $error_birthday_year == 1}class="fielderror"{/if}> {section name=years loop=$bday_y} <option label="{$bday_y[years].name}" value="{$bday_y[years].value}" {if $post.birthday_year == $bday_y[years].value}SELECTED{/if}>{$bday_y[years].name}</option> {/section} </select>