ðHTMLã§ãã©ãŒã äœæð
ðãã©ãŒã
form
èŠçŽ
<form action=â#â method=âPOSTâ>
</form>
ã»action
å±æ§ãã©ãã«ããŒã¿ãéä¿¡ããããèšè¿°
ã»method
å±æ§ãHTTPãªã¯ãšã¹ãã¡ãœããã®çš®é¡ãèšè¿°
ðHTTPãªã¯ãšã¹ãã¡ãœãããšã¯
ãã©ãŠã¶ãããµãŒããŒã«å¯ŸããŠäŸé ŒããåŠçã®çš®é¡
å©çšé »åºŠãé«ã
ð±GETã
ãµãŒããŒããããŒã¿ãååŸããããšã
äŸïŒWebããŒãžãååŸïŒè¡šç€ºïŒãç»åãååŸ(ããã°ã®æŽæ°æ
å ±ãååŸ)RSSãã£ãŒãã®ååŸ
ð±POST
ãµãŒããžããŒã¿ãéä¿¡ããããšã
äŸïŒãã°ã€ã³ãã©ãŒã ãECãµã€ãã§ã®åå泚æãã©ãŒã ãã¢ã³ã±ãŒããéä¿¡
ðinputèŠçŽ
ããŒã¿ãå
¥åããããã®ãã©ãŒã éšåãäœãèŠçŽ
typeå±æ§ãæå®ããããšã§æ§ã
ãªå
¥åãã©ãŒã ãäœæå¯èœ
äŸïŒ
<input type=âtextâ>
â ïžçµäºã¿ã°ãä»ããªãã空èŠçŽ
MDN form input ã§æ€çŽ¢
ãã©ãŒã ã®<input>ã®åãåç
§ïŒïŒ
ðãååããã©ãŒã ã®å¶äœ
ð±ãååããã©ãŒã
<form action="#" method="POST">
<input type="text" name="username" placeholder="ãŠãŒã¶ãŒããŒã ">
<input type="password" name="password" placeholder="ãã¹ã¯ãŒã">
<input type="submit" value="ãã°ã€ã³">
</form>
ð±ãã«ããŠã³ã¡ãã¥ãŒ
- 芪èŠçŽ ãselectèŠçŽ ã«å®çŸ©
- éžæè¢ãoptionèŠçŽ ã§å®çŸ©
<dt>ãäœãŸãã®å°å</dt>
<dd>
<select name="area">
<option value="" selected>éžæããŠãã ãã</option>
<option value="hokkaido">åæµ·é</option>
<option value="tohoku">æ±å</option>
<option value="kanto">é¢æ±</option>
<option value="chubu">äžéš</option>
<option value="kinki">è¿ç¿</option>
<option value="shikoku">ååœ</option>
<option value="kyusyu">ä¹å·</option>
<option value="okinawa">æ²çž</option>
</select>
Ï(
selectedå±æ§ã«ã¯å€ããªã
optionã«èšå®ãããšéžæè¢ãåæç¶æ
ã§éžæããã
â ïžselectèŠçŽ å
ã§ïŒåã®optionã ããselectedå±æ§ãããŠã
dd>select>option*9
ð±ã©ãžãªãã¿ã³
æ§å¥å ¥åéšå
<dt>æ§å¥</dt>
<dd>
<input type="radio" name="gender" value="male" checked>ç·æ§
<input type="radio" name="gender" value="female">女æ§
</dd>
</dd>
Ï(
checkedãã€ãããšåæç¶æ
ã§éžæããããç¶æ
ã«ãªã
ð±ããã¹ããšãªã¢
ãååãå 容éšå
<dt>ãååãå
容</dt>
<dd><textarea name="contents"></textarea></dd>
Ï(
çµäºã¿ã°ã¯å¿
èŠ
inputã§çµ±äžããã»ããçŸãããšããæèŠããããçŸç¶ã¯ãã®ä»æ§ãªã®ã§åŸãå¿
èŠãã
nameå±æ§ã¯ããŒã¿ããµãŒããŒåŽãåãåã£ããšãã«äœã®ããŒã¿ããå€å¥ããããã«ã€ããååïŒ
ð±ãã§ãã¯ããã¯ã¹
ãã©ã€ãã·ãŒããªã·ãŒã®åæãããã§ãã¯ãããæ©èœ
<dt>ãã©ã€ãã·ãŒããªã·ãŒã«åæãã</dt>
<dd><input type="checkbox" name="privacy" value="1" ></dd>
Ï(
ãã§ãã¯ããã¯ã¹ãäœãã«ã¯typeã«checkboxãæå®
checkedãã€ãããšåæç¶æ
ã§éžæããããç¶æ
ã«ãªã
ð±éä¿¡ãã¿ã³
éä¿¡ãã¿ã³ã«ã€ããŠ
Submit=æåºãããšããæå³åã
dlã¿ã°ã®äžã«èšè¿°
<input type="submit" name="submit" value="éä¿¡">
- valueã¯ãã¿ã³ã®ã©ãã«ã®ããã¹ããèšèŒ
- ãµãŒããŒåŽã®ããã°ã©ã ã¯çšæããŠãªãã®ã§éä¿¡ã¯ãããªããã
å®éã¯formèŠçŽ ã®actionå±æ§ã«æå®ãããã¹ã«ããŒã¿ãéä¿¡ããã
ð±ã©ãã«
åãã©ãŒã éšåãäœã®å ¥åæ¬ã瀺ããŠããã®ãã説æããããã®ããã¹ã
ã©ãã«èŠçŽ
<dt><label for="username">ãåå</label></dt>
<dd><input id="username" type="text" name="username"></dd>
ããã¹ããã©ãã«ã§å²ã
ã©ãã«ãã€ãããèŠçŽ ã«idãæ¯ã
ã©ãã«ã®forå±æ§ã«forméšåã®idãæå®
Ï(
ã©ãžãªãã¿ã³ã®ã©ãã«ãã©ãèšè¿°ãããã«ã€ããŠã¯è€æ°ã®æ¹æ³ããã
ä»åã¯ãåãã©ãŒã éšåãã©ãã«èŠçŽ ã§å²ã
èšãæãããšforå±æ§ã®ä»£ããã«inputèŠçŽ ãã©ãã«èŠçŽ ã§å²ãããš
<dt>æ§å¥</dt>
<dd>
<label><input type="radio" name="gender" value="male" checked>ç·æ§</label>
<label><input type="radio" name="gender" value="female">女æ§</label>
</dd>
</dd>
ã©ãã«ãèšè¿°ããæ¹æ³ãšããŠãã
- ã©ãã«ã®forå±æ§ã䜿ãæ¹æ³
- ã©ãã«èŠçŽ ã§forméšåãå²ã
ïŒéãã®æ¹æ³ããããã䜿ããããæ¹ã䜿ãã°OKðð»ââïž
ð§ð»ã©ãã«ã䜿ãã¡ãªãã
- ææžã®æå³ä»ããããæ£ããã§ãã
- ãã§ãã¯ããã¯ã¹ãã©ãžãªãã¿ã³ã§ãã©ãã«ã®éšåïŒããã¹ãïŒãã¯ãªãã¯ããŠããéžæã§ããããã«ãªã
ð±ãã©ãŒã ããªããŒã·ã§ã³
ããªããŒã·ã§ã³ãšã¯ãã
å
¥åãããå
容ãèŠä»¶ãæºãããŠãããã劥åœæ§ã確èªããããš
ðŒå ¥åå¿ é å¶çŽãä»ãã
<form action="#" method="POST">
<input type="text" required>
<input type="submit" value="éä¿¡">
</form>
Ï(
required
å±æ§ãã€ãããšãšã©ãŒè¡šç€ºãåºãŠæ¬¡ã«é²ããªãããã«ã§ãã
ïŒã¯ãããŒ
ðŒæåæ°å¶é
ïŒæåãŸã§å
¥åãèš±å¯ããããïŒæå以äžã¯å
¥åã§ããªãããã«èšå®
<form action="#" method="POST">
<input type="text" required maxlength="5">
<input type="submit" value="éä¿¡">
</form>
â ïžãã®ã¯ã©ã€ã¢ã³ãåŽã®ããã©ãŒã ããªãšãŒã·ã§ã³ã¯ããŠãŒã¶ãŒãç°¡åã«æžãæãããã
HTMLã®ãã©ãŒã ããªããŒã·ã§ã³ã¯ãäžæ£å¯Ÿçã«ã¯äœ¿ããªã
ðãã©ãŒã ããéãããŠããå€ã¯ä¿¡é Œã§ããªãå Žåãããç¹ã¯èŠããŠããïŒ
察çãšããŠã¯ããµãŒããŒãµã€ãåŽã®ãã©ãŒã ããã®ããŒã¿ãåãåãããã°ã©ã åŽã§ã
å€ã®æ£åœæ§ãã§ãã¯ãè¡ãïŒïŒ
ðã¯ã©ã€ã¢ã³ãåŽã®ãã©ãŒã ããŒã¿æ€èšŒ
HTMLã¹ãããã¢ããç·šçµäºïŒ
ææ¥ããã¯CSSã®åºæ¬ç¿åŸãžã
å¹³æ¥ã¯ããã«æ®æ¥ããã«å®¶ã«åž°ã£ãŠããããã®åè² ïŒ
å¹çè¯ãé²ããŠãããð¥ð¥
Discussion