Form ํ๊ทธ
Form ํ๊ทธ
ํผ(Form): ์ฌ์ฉ์์ ์ ๋ณด๋ฅผ ์ ๋ ฅ๋ฐ์ ์ ์๊ฒ ๋ง๋ค์ด ๋์ ํ์
ex) ๋ก๊ทธ์ธ, ํ์๊ฐ์ , ๊ฒ์ํ ๊ธ์ฐ๊ธฐ ๋ฑ
→ ํผ: ์ ๋ ฅ๋ฐ๋ ๋ฐ์ดํฐ๋ค์ ๋ฌถ์ / ํผ ๋ฐ์ดํฐ ๋๋ ํ๋: ๋ฐ์ดํฐ
<form> ์์๋ ์ ๋ณด๋ฅผ ์ ์ถํ๊ธฐ ์ํด ์ด๋์๋ถํฐ ์ด๋๊น์ง๊ฐ ์์์ธ์ง ์ง์ ํ๋ ์ญํ
<form action="/signup" method="post">
<div class="form-example">
<label for="name">์ด๋ฆ: <label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-example">
<label for="email">์ด๋ฉ์ผ: <email>
<input type="email" name="email" id="email" required>
</div>
<div class="form-example">
<input type="submit" value="์ ์ถํ๊ธฐ">
</div>
</form>
์์ฑ
- action: ์์ ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ ์๋ฒ ํ๋ก๊ทธ๋จ์ URI
- method: ์์์ ์ ์ถํ ๋ ์ฌ์ฉํ HTTP ๋ฉ์๋
- post: ์์ ๋ฐ์ดํฐ๋ฅผ ์์ฒญ ๋ณธ๋ฌธ์ผ๋ก ์ ์ก
- get: ์์ ๋ฐ์ดํฐ๋ฅผ URL์ ์ฟผ๋ฆฌ์คํธ๋ง์ผ๋ก ๋ถ์ฌ์ ์ ์ก
Input ํ๊ทธ
<input> ์์๋ก ๋ฐ์ดํฐ๋ฅผ ์ ๋ ฅ ๋ฐ์ ์ ์๋ค.
text
<input> ํ๊ทธ์ ๊ธฐ๋ณธ ๊ฐ์ผ๋ก ํ ์ค์ ํ ์คํธ๋ฅผ ์ ๋ ฅ ๋ฐ๋๋ค.
<input type="text" id="name">
- email: email ๋ฐ์ดํฐ๋ฅผ ๋ฐ๊ธฐ์ํด ์ฌ์ฉ๋จ (์ด๋ฉ์ผ ์ ํจ์ฑ ๊ฒ์ฆ)
- tel: ์ ํ๋ฒํธ๋ฅผ ๋ฐ๊ธฐ ์ํด ์ฌ์ฉ๋จ (๋ชจ๋ฐ์ผ ์ ๊ทผ์ ํคํจ๋ ๋ค๋ฆ)
label
<label> ๋ ์ด๋ธ ํ๊ทธ๋ ์ ๋ ฅ๋ฐ๋ ํ๋๋ฅผ ์ค๋ช ํ ๋ ์ฌ์ฉ (์น ์ ๊ทผ์ฑ ์ค์)
<!-- label ํ๊ทธ ํ์์ ๋๋ ๋ฒ -->
<label>
์ด๋ฆ:
<input type="text" id="name">
</label>
<!-- for์ id์์ฑ์ ์ฌ์ฉํ์ฌ label ํ๊ทธ์ ์ฐ๊ฒฐ์ง์ -->
<label for="name">์ด๋ฆ : </label>
<input type="text" id="name">
fieldset
์์์ ์ฌ๋ฌ ์ปจํธ๋กค๊ณผ ๋ ์ด๋ธ(<label>)์ ๋ฌถ์ ๋ ์ฌ์ฉ
legend
์์๋ ๋ถ๋ชจ <fieldset>์ฝํ ์ธ ์ ์ค๋ช ์ ๋ํ๋
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Form Input</title>
</head>
<body>
<form action="">
<fieldset>
<legend>Input Tag</legend>
<ul>
<li>
<label for="text">Text</label>
<input type="text" id="text" required value="weoifj" readonly />
</li>
<li>
<label for="email">์ด๋ฉ์ผ</label>
<input type="email" id="email" required value="hello" disabled />
</li>
<li>
<label for="tel">์ ํ๋ฒํธ</label>
<input type="tel" id="tel" required autofocus />
</li>
<li>
<label for="url">url</label>
<input
type="url"
id="url"
required
placeholder="url์ ์
๋ ฅํด์ฃผ์ธ์"
/>
</li>
<li>
<label for="number">number</label>
<input type="number" id="number" required min="5" max="10" />
</li>
<li>
<label for="range">range</label>
<input type="range" id="range" required />
</li>
<li>
<label for="password">password</label>
<input type="password" id="password" required />
</li>
</ul>
</fieldset>
<fieldset>
<legend>๋ ์ง๊ด๋ จ</legend>
<ul>
<li>
<label for="date">date</label>
<input type="date" id="date" min="2022-08-20" max="2022-08-30" />
</li>
<li>
<label for="month">month</label>
<input type="month" id="month" />
</li>
<li>
<label for="week">week</label>
<input type="week" id="week" />
</li>
</ul>
</fieldset>
<fieldset>
<legend>์๊ฐ๊ด๋ จ</legend>
<ul>
<li>
<label for="time">time</label>
<input type="time" id="time" min="16:00" max="10:00" />
</li>
</ul>
</fieldset>
<fieldset>
<legend>๊ทธ ์ธ</legend>
<ul>
<li>
<input type="file" multiple />
</li>
<li>
<input type="hidden" name="" value="" />
</li>
</ul>
</fieldset>
<input type="submit" value="์ ์ถํ๊ธฐ" />
</form>
</body>
</html>
Form ๋ฐ์ดํฐ ํ๊ทธ ์์ฑ
- required
- ์ ๋ ฅ๊ฐ์ด ํ์๋ผ๋ ๊ฒ์ ๋ช ์
- readonly
- ํ๋๋ฅผ ์ฝ๊ธฐ ์ ์ฉ์ผ๋ก ํ๋๋ก ๋ง๋ฆ
- disabled
- ๋นํ์คํ ์ํฌ ์ ์์ผ๋ฉฐ, ํด๋น ํ๋๋ ์๋ฒ๋ก ์ ์ก๋์ง ์์
- autofocus
- ์ด๊ธฐ์ ํด๋น ํ๋์ ์ปค์๋ฅผ ์์น ์ํฌ ์ ์์
- placeholder
- ์ ๋ ฅ ํ๋๊ฐ ๋น์ด์์ ๋ ํด๋น ์ ๋ ฅ๊ฐ์ ์ค๋ช ๋๋ ๊ฐ์ด๋ ๋ฌธ๊ตฌ๋ฅผ ์ฝ์ ํ ์ ์์
checkbox
์ฌ๋ฌ ๊ฐ์ ์ฒดํฌ๋ฐ์ค ํญ๋ชฉ ์ค 2๊ฐ ์ด์ ์ ํํ ์ ์์. ์ ํ๋ ์ฒดํฌ๋ฐ์ค์ value๊ฐ์ด ์๋ฒ๋ก ์ ์ก
<ul>
<li>
<label for="apple">์ฌ๊ณผ</label>
<input id="apple" type="checkbox" value="apple">
</li>
<li>
<label for="orange">์ค๋ ์ง</label>
<input id="orange" type="checkbox" value="orange">
</li>
<li>
<label for="banana">๋ฐ๋๋</label>
<input id="banana" type="checkbox" value="banana">
</li>
</ul>
radio
์ฌ๋ฌ ๊ฐ์ ๋ผ๋์ค ํญ๋ชฉ ์ค 1๊ฐ๋ฅผ ์ ํ ๊ฐ๋ฅ, ์ ํ๋ ์ฒดํฌ๋ฐ์ค์ value๊ฐ์ด ์๋ฒ๋ก ์ ์ก
→ ์ฌ๋ฌ ๊ฐ ์ค ํ๋๋ฅผ ์ ํํ๊ฒ ํ๋ ค๋ฉด ๊ทธ ์ฌ๋ฌ ํญ๋ชฉ์ <radio name=””> name ์์ฑ ๊ฐ์ ๊ฐ์ ๊ฐ์ผ๋ก ๊ทธ๋ฃนํ ํด์ค์ผ ํจ
<ul>
<li>
<label for="strawberry">๋ธ๊ธฐ</label>
<input id="strawberry" type="radio" name="fruit" value="strawberry">
</li>
<li>
<label for="grape">ํฌ๋</label>
<input id="grape" type="radio" name="fruit" value="grape">
</li>
<li>
<label for="peach">๋ณต์ญ์</label>
<input id="peach" type="radio" name="fruit" value="peach">
</li>
</ul>
Textarea
<textarea>๋ ์ฌ๋ฌ ์ค์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ ฅ๋ฐ์ ์ ์์
<textarea id="story" name="story" rows="5" cols="33">
It was a dark and stormy night...
</textarea>
- rows: ํ๋ฉด์ ํ์๋๋ ํ ์
- cols: ํ๋ฉด์ ํ์๋๋ ์ปฌ๋ผ ์
Select
<select>ํ๊ทธ๋ ์ต์ ๋ฉ๋ด๋ฅผ ์ ๊ณต, <option>ํ๊ทธ๋ก ๊ฐ ํญ๋ชฉ์ ๋ํ๋ด๋ฉฐ, <select>ํ๊ทธ๋ <option>ํ๊ทธ๋ฅผ ๊ฐ์ธ์ค
<select name="goods" id="goods">
<option value="10kg">์ฌ๊ณผ 10kg</option>
<option value="20kg" selected>์ฌ๊ณผ 20kg</option>
<option value="30kg">์ฌ๊ณผ 30kg</option>
<option value="40kg">์ฌ๊ณผ 40kg</option>
<option value="50kg">์ฌ๊ณผ 50kg</option>
</select>
- selected ์์ฑ์ ํ์ฌ <select> ์์์์ ์ ํ๋ ํญ๋ชฉ(<option>)์ ๊ฐ๋ฆฌํด
datalist
๋ค๋ฅธ ์ปจํธ๋กค์์ ๊ณ ๋ฅผ ์ ์๋ ๊ฐ๋ฅํ, ํน์ ์ถ์ฒํ๋ ์ ํ์ง๋ฅผ ๋ํ๋ด๋ <option>์์ ์ฌ๋ฟ์ ๋ด์
<label for="ice-cream-choice">๋ง์ ์ ํํ์ธ์</label>
<input list="ice-cream-flavors" id="ice-cream-choice" name="ice-cream-choice" />
<datalist id="ice-cream-flavors">
<option value="chocolate">
<option value="coconut">
<option value="mint">
<option value="strawberry">
<option value="vanilla">
</datalist>
Button
<button>์์๋ ํด๋ฆญ ๊ฐ๋ฅํ ๋ฒํผ์ ๋ํ๋, <form>๋ด๋ถ์ ๋ฒํผ ๊ธฐ๋ฅ์ด ํ์ํ ๊ณณ์ด๋ผ๋ฉด ์ด๋์๋ ๋ฐฐ์น ๊ฐ๋ฅ
<button type="button">
์ถ๊ฐํ๊ธฐ
</button>
Type
- submit: ๋ฒํผ์ด ์๋ฒ๋ก ์์ ๋ฐ์ดํฐ๋ฅผ ์ ์ถ(๊ธฐ๋ณธ ๊ฐ)
- reset: <input type=”reset”>์ฒ๋ผ, ๋ชจ๋ ์ ๋ ฅ ํ๋๋ฅผ ์ด๊ธฐ๊ฐ์ผ๋ก ๋๋๋ฆผ
- button: ๊ธฐ๋ณธ ํ๋์ด ์์ผ๋ฉฐ ์ฃผ๋ก ํด๋ฆญ ํ ํ ์๋ฐ์คํฌ๋ฆฝํธ ์ธก ์ฝ๋๋ฅผ ๋ช ๋ นํ ๋ ์ฌ์ฉ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Radio & Checkbox</title>
</head>
<body>
<form action="">
<fieldset>
<legend>์ข์ํ๋ ์์์ ๋ชจ๋ ์ ํํด์ฃผ์ธ์.</legend>
<ul>
<li>
<label for="red">๋นจ๊ฐ</label>
<input type="checkbox" id="red" value="red" />
</li>
<li>
<label for="orange">์ฃผํฉ</label>
<input type="checkbox" id="orange" value="orange" />
</li>
<li>
<label for="yellow">๋
ธ๋</label>
<input type="checkbox" id="yellow" value="yellow" />
</li>
<li>
<label for="blue">ํ๋</label>
<input type="checkbox" id="blue" value="blue" />
</li>
<li>
<label for="green">์ด๋ก</label>
<input type="checkbox" id="green" value="green" />
</li>
</ul>
</fieldset>
<fieldset>
<legend>๋ฐฐ์ก๋ฐฉ๋ฒ์?</legend>
<ul>
<li>
<label for="free">๋ฌด๋ฃ</label>
<input type="radio" name="delivery" id="free" value="free" />
</li>
<li>
<label for="pay">์ ๋ฃ</label>
<input type="radio" name="delivery" id="pay" value="pay" />
</li>
</ul>
</fieldset>
<fieldset>
<legend>์๊ธฐ์๊ฐ์</legend>
<textarea name="" id="" cols="30" rows="5">์ ๋ ํ๊ธธ๋์
๋๋ค.</textarea>
</fieldset>
<fieldset>
<legend>์ฃผ๋ฌธ ์ํ์ ์ ํํด์ฃผ์ธ์!</legend>
<ul>
<li>
<select name="goods" id="goods" multiple>
<option value="apple_10kg">์ฌ๊ณผ 10kg</option>
<option value="apple_20kg" selected>์ฌ๊ณผ 20kg</option>
<option value="apple_30kg">์ฌ๊ณผ 30kg</option>
<option value="apple_40kg">์ฌ๊ณผ 40kg</option>
<option value="apple_50kg">์ฌ๊ณผ 50kg</option>
</select>
</li>
<li>
<label for="ice-cream-choice">๋ง์ ์ ํํ์ธ์</label>
<input
list="ice-cream-flavors"
id="ice-cream-choice"
name="ice-cream-choice"
/>
<datalist id="ice-cream-flavors">
<option value="chocolate"></option>
<option value="coconut"></option>
<option value="mint"></option>
<option value="strawberry"></option>
<option value="vanilla"></option>
</datalist>
</li>
</ul>
</fieldset>
<button type="submit">์ ์ถํ๊ธฐ</button>
<button type="reset">๋ฆฌ์
ํ๊ธฐ</button>
<button type="button" onclick="alert('hello')">๋ฒํผ</button>
</form>
</body>
</html>'ํ๋ก ํธ์๋ > HTML' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| Head ํ๊ทธ (0) | 2022.11.18 |
|---|---|
| ์ด๋ฏธ์ง & ๋ฉํฐ๋ฏธ๋์ด ํ๊ทธ (0) | 2022.11.18 |
| Block ๋ ๋ฒจ ์์์ Inline ๋ ๋ฒจ ์์ (0) | 2022.11.18 |
| Semanticํ๊ทธ (0) | 2022.11.18 |
| Tableํ๊ทธ (0) | 2022.11.18 |