ํผ ๊ตฌ์ฑ
- ํผ(form)์ HTML์์ ์ฌ์ฉ์์ ์ํธ์์ฉํด์ ์ ๋ณด๋ฅผ ์
๋ ฅ ๋ฐ๊ณ ์๋ฒ๋ก ์ ์กํ๊ธฐ ์ํ ์์์ ์๋ฏธ
form ํ๊ทธ
<form action="์ฒ๋ฆฌํ ํ์ด์ง์ฃผ์" method="get|post"></form>
action ์์ฑ
- ํผ ์์์์ ์ฌ์ฉ์์ ์ํธ์์ฉ์ผ๋ก ์
๋ ฅ ๋ฐ์ ๊ฐ๋ค์ ์ ์กํ ์๋ฒ์ URL ์ฃผ์ ์์ฑ
method ์์ฑ
- ์
๋ ฅ ๋ฐ์ ๊ฐ์ ์๋ฒ์ ์ ์กํ ๋ ์ก์ ๋ฐฉ์ ์์ฑ
- ์์ฑ ๊ฐ์ผ๋ก get ๋๋ post ์ฌ์ฉ
GET ๋ฐฉ์์ ์ฃผ์์ ๋ฐ์ดํฐ(data)๋ฅผ ์ถ๊ฐํ์ฌ ์ ๋ฌํ๋ ๋ฐฉ์์
๋๋ค.
๋ฐ์ดํฐ๊ฐ ์ฃผ์ ์
๋ ฅ์ฐฝ์ ๊ทธ๋๋ก ๋ํ๋๋ฉฐ, ์ ์กํ ์ ์๋ ๋ฐ์ดํฐ์ ํฌ๊ธฐ ๋ํ ์ ํ์ ์
๋๋ค.
๋ฐ๋ผ์ ๊ฒ์ ์์ง์ ์ฟผ๋ฆฌ(query)์ ๊ฐ์ด ํฌ๊ธฐ๊ฐ ์๊ณ ์ค์๋๊ฐ ๋ฎ์ ์ ๋ณด๋ฅผ ๋ณด๋ผ ๋ ์ฃผ๋ก ์ฌ์ฉํฉ๋๋ค.
POST ๋ฐฉ์์ ๋ฐ์ดํฐ(data)๋ฅผ ๋ณ๋๋ก ์ฒจ๋ถํ์ฌ ์ ๋ฌํ๋ ๋ฐฉ์์
๋๋ค.
๋ฐ์ดํฐ๊ฐ ์ธ๋ถ์ ๋๋ฌ๋์ง ์์ผ๋ฉฐ, ์ ์กํ ์ ์๋ ๋ฐ์ดํฐ์ ํฌ๊ธฐ ๋ํ ์ ํ์ด ์์ต๋๋ค.
๋ฐ๋ผ์ ๋ณด์์ฑ ๋ฐ ํ์ฉ์ฑ์ด GET ๋ฐฉ์๋ณด๋ค ์ข์ต๋๋ค.
input ํ๊ทธ
- ๋ก๊ทธ์ธ ํ์ด์ง์ ์์ด๋์ ๋น๋ฐ๋ฒํธ์ฒ๋ผ ์
๋ ฅ๋ฐ๋ ์์๋ฅผ ์์ฑํ ๋ ์ฌ์ฉ
<input type="์ข
๋ฅ" name="์ด๋ฆ" value="์ด๊ธฐ๊ฐ">
type ์์ฑ
- ๋ค์ํ ํ์
์ ์
๋ ฅ ์์๋ฅผ ๋ง๋ค๊ธฐ ์ํด type ์์ฑ๊ฐ์ผ๋ก ๋ค์๊ณผ ๊ฐ์ ๊ฐ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- text: ํ
์คํธ ์
๋ ฅ๋์ ๋ง๋ญ๋๋ค.
- password: ๋น๋ฐ๋ฒํธ ์
๋ ฅ๋์ ๋ง๋ญ๋๋ค.
- checkbox: ์ฒดํฌ๋ฐ์ค๋ฅผ ๋ง๋ญ๋๋ค.
- radio: ๋ผ๋์ค ๋ฒํผ์ ๋ง๋ญ๋๋ค.
- submit: ์ ์ถ ๋ฒํผ์ ๋ง๋ญ๋๋ค.
- reset: ๋ฆฌ์
๋ฒํผ์ ๋ง๋ญ๋๋ค.
- button: ์ผ๋ฐ ๋ฒํผ์ ๋ง๋ญ๋๋ค.
- hidden: ํ๋ฉด์ ๋ณด์ด์ง ์๋ ์จ๊ฒจ์ง ์
๋ ฅ๋์ ๋ง๋ญ๋๋ค.
- date: ๋ ์ง ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- time: ์๊ฐ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- datetime: ๋ ์ง์ ์๊ฐ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- email: ์ด๋ฉ์ผ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- file: ํ์ผ ์
๋ก๋ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- image: ์ด๋ฏธ์ง๋ฅผ ๋ํ๋ด๋ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- month: ์ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- number: ์ซ์ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- range: ๋ฒ์๋ฅผ ์ ํํ๋ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- search: ๊ฒ์ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- tel: ์ ํ๋ฒํธ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- url: URL ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- week: ์ฃผ ๋จ์ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
- color: ์์ ์ ํ ์
๋ ฅ ์์๋ฅผ ๋ง๋ญ๋๋ค.
<input type="text" name="username">
<input type="password" name="password">
<input type="checkbox" name="check">
<input type="radio" name="radio" value="1">
<input type="submit" value="์ ์ถ">
<input type="reset" value="์ด๊ธฐํ">
<button type="button">๋ฒํผ</button>
<input type="hidden" name="hidden_input">
<input type="date" name="date_input">
<input type="time" name="time_input">
<input type="datetime" name="datetime_input">
<input type="email" name="email_input">
<input type="file" name="file_input">
<input type="image" src="image.jpg">
<input type="month" name="month_input">
<input type="number" name="number_input">
<input type="range" name="range_input">
<input type="search" name="search_input">
<input type="tel" name="tel_input">
<input type="url" name="url_input">
<input type="week" name="week_input">
<input type="color" name="color_input">
๋ผ๋์ค ํ์
- name : name์ ๊ฐ์ด ๊ฐ์ ๊ฒ ์ค์์ ํ๋ ์ ํ
- value : ์ ํํ์ ๋ ์ ๋ฌ๋ ๊ฐ
- checked : ์ ํ๋ ์ํ๋ก ๋ง๋ ๋ค.
<form action="">
<label for="male">๋จ์ฑ</label>
<input type="radio" name="gender" id="male">
<label for="famale">์ฌ์ฑ</label>
<input type="radio" name="gender" id="famale">
</form>
label ํ๊ทธ
- from ํ๊ทธ ์์์ ์ฌ์ฉํ๋ ์ํธ์์ฉ ์์์ ์ด๋ฆ์ ๋ถ์ผ ๋ ์ฌ์ฉ
- ์๊ฐ ์ฅ์ ์ธ์ด ์น์ ํ์ํ ๋ ์คํฌ๋ฆฐ ๋ฆฌ๋(์น ์ ๊ทผ์ฑ) label ํ๊ทธ๋ก ์ฐ๊ฒฐ๋ ์ํธ์์ฉ ์์๋ฅผ ์ฝ์ด ์ฃผ๋ ์์๋ก ์ฌ์ฉ
<label for="user-id">์์ด๋(6์๋ฆฌ ์ด์)</label>
<input type="text" id="user-id">
fieldset, legend ํ๊ทธ
- form ํ๊ทธ ์์ ์ฌ์ฉ๋ ๋ค์ํ ์ํธ์์ฉ ์์๋ fieldset ํ๊ทธ๋ฅผ ์ฌ์ฉํด ๊ทธ๋ฃน์ ์ง์ ์ ์์
- fieldset ํ๊ทธ๋ก ๊ทธ๋ฃน์ ์ง์ผ๋ฉด ๊ทธ๋ฃน๋ณ๋ก ๋ฐ์ค ๋ชจ์์ ํ
๋๋ฆฌ๊ฐ ์๊น.
<body>
<form>
<fieldset>
<legend>๊ธฐ๋ณธ ์ ๋ณด</legend>
<p>
<label for="userid">์์ด๋</label>
<input type="text" id="userid">
</p>
<p>
<label for="passwd">๋น๋ฐ๋ฒํธ</label>
<input type="password" id="passwd">
</p>
</fieldset>
<fieldset>
<legend>์ ํ ์ ๋ณด</legend>
<p>
<label for="age">๋์ด</label>
<input type="number" id="age">
</p>
<p>
<label for="recommender">์ถ์ฒ์ธ</label>
<input type="text" id="recommender">
</p>
</fieldset>
</form>
</body>
textarea ํ๊ทธ
- ์ฌ๋ฌ ์ค์ ์
๋ ฅ ์์๋ฅผ ์์ฑํ ๋ ์ฌ์ฉ
- ์น ์ฌ์ดํธ์์ ๊ธ์ ์์ฑํ ๋ ์ฌ์ฉํ๋ ์
๋ ฅ ์์๋ ๋๋ถ๋ถ textarea ํ๊ทธ๋ก ์์ฑ
<body>
<form action="#" method="post">
<fieldset>
<legend>๋ธ๋ก๊ทธ ๊ธ์ฐ๊ธฐ</legend>
<p>
<label for="title">์ ๋ชฉ
<input type="text" id="title" name="title">
</label>
</p>
<p>
<label for="desc">๋ด์ฉ
<textarea id="desc" name="desc" readonly></textarea>
</label>
</p>
</fieldset>
</form>
</body>
select, option, optgroup ํ๊ทธ
- select : ์ฝค๋ณด ๋ฐ์ค
- option : ์ฝค๋ณด ๋ฐ์ค์ ์ต์
์ถ๊ฐ
- optgroup : ํญ๋ชฉ๋ค ๊ทธ๋ฃน์ผ๋ก ๋ฌถ์ ๋ ์ฌ์ฉ
- optgroup ํ๊ทธ๋ก ํญ๋ชฉ๋ค์ ๊ทธ๋ฃน ์ง์ ๋๋ ๋ฐ๋์ label ์์ฑ์ผ๋ก ๊ทธ๋ฃน๋ช
์ง์ ํด์ผ ํจ.
select, option ํ๊ทธ ์ฌ์ฉ ์์
<body>
<!-- select & option ํ๊ทธ๋ง ์ฌ์ฉ -->
<form action="#" method="post">
<fieldset>
<legend>๊ฐ์ธ ์ ๋ณด ์
๋ ฅ</legend>
<label for="city">์ง์ญ</label>
<select name="city" id="city">
<option value="๊ฐ๋ถ๊ตฌ">๊ฐ๋ถ๊ตฌ</option>
<option value="๊ฐ๋จ๊ตฌ">๊ฐ๋จ๊ตฌ</option>
<option value="์์ด๊ตฌ">์์ด๊ตฌ</option>
<option value="์ค์๊ตฌ">์ค์๊ตฌ</option>
<option value="๋ถ๋น๊ตฌ">๋ถ๋น๊ตฌ</option>
</select>
<input type="submit" value="๋ฑ๋ก">
</fieldset>
</form>
</body>
optgroup ํ๊ทธ ์ฌ์ฉ ์์
<body>
<!-- select & option & optgroup ํ๊ทธ ์ฌ์ฉ-->
<form action="#" method="post">
<fieldset>
<legend>๊ฐ์ธ ์ ๋ณด ์
๋ ฅ</legend>
<label for="city">์ง์ญ</label>
<select name="city" id="city">
<optgroup label="์์ธ์">
<option value="๊ฐ๋ถ๊ตฌ">๊ฐ๋ถ๊ตฌ</option>
<option value="๊ฐ๋จ๊ตฌ">๊ฐ๋จ๊ตฌ</option>
<option value="์์ด๊ตฌ">์์ด๊ตฌ</option>
</optgroup>
<optgroup label="๊ฒฝ๊ธฐ๋ ์ฑ๋จ์">
<option value="์ค์๊ตฌ">์ค์๊ตฌ</option>
<option value="๋ถ๋น๊ตฌ">๋ถ๋น๊ตฌ</option>
</optgroup>
</select>
<input type="submit" value="๋ฑ๋ก">
</fieldset>
</form>
</body>
size ์์ฑ
- ์ฝค๋ณด๋ฐ์ค์์ ํ๋ฉด์ ๋
ธ์ถ๋๋ ํญ๋ชฉ ๊ฐฏ์ ์ง์
<body>
<!-- select & option ํ๊ทธ๋ง ์ฌ์ฉ -->
<form action="#" method="post">
<fieldset>
<legend>๊ฐ์ธ ์ ๋ณด ์
๋ ฅ</legend>
<label for="city">์ง์ญ</label>
<select name="city" id="city" size="3">
<option value="๊ฐ๋ถ๊ตฌ">๊ฐ๋ถ๊ตฌ</option>
<option value="๊ฐ๋จ๊ตฌ">๊ฐ๋จ๊ตฌ</option>
<option value="์์ด๊ตฌ">์์ด๊ตฌ</option>
<option value="์ค์๊ตฌ">์ค์๊ตฌ</option>
<option value="๋ถ๋น๊ตฌ">๋ถ๋น๊ตฌ</option>
</select>
<input type="submit" value="๋ฑ๋ก">
</fieldset>
</form>
</body>
multiple ์์ฑ
- select ํ๊ทธ๋ก ์์ฑํ๋ ์ฝค๋ณด๋ฐ์ค๋ ๊ธฐ๋ณธ์ผ๋ก 1๊ฐ ํญ๋ชฉ๋ง ์ ํ ํ ์ ์์ต๋๋ค.
๊ทธ๋ฌ๋ multiple ์์ฑ์ ์ฌ์ฉํ๋ฉด ์ฌ๋ฌ ํญ๋ชฉ์ ๋์์ ์ ํ ํ ์ ์์ต๋๋ค.
- ์ฝค๋ณด๋ฐ์ค์์ ํญ๋ชฉ ํ๋๋ฅผ ์ ํํ ์ํ๋ก Ctrl (๋งฅOS์์๋ cmd)์ ๋๋ฅด๊ณ ๋ค์ ํญ๋ชฉ์ ํด๋ฆญํ๋ฉด ๋ฉ๋๋ค.
<body>
<!-- select & option ํ๊ทธ๋ง ์ฌ์ฉ -->
<form action="#" method="post">
<fieldset>
<legend>๊ฐ์ธ ์ ๋ณด ์
๋ ฅ</legend>
<label for="city">์ง์ญ</label>
<select name="city" id="city" multiple>
<option value="๊ฐ๋ถ๊ตฌ">๊ฐ๋ถ๊ตฌ</option>
<option value="๊ฐ๋จ๊ตฌ">๊ฐ๋จ๊ตฌ</option>
<option value="์์ด๊ตฌ">์์ด๊ตฌ</option>
<option value="์ค์๊ตฌ">์ค์๊ตฌ</option>
<option value="๋ถ๋น๊ตฌ">๋ถ๋น๊ตฌ</option>
</select>
<input type="submit" value="๋ฑ๋ก">
</fieldset>
</form>
</body>
selected ์์ฑ
- selected ์์ฑ์ ์ฌ์ฉํ๋ฉด ๊ธฐ๋ณธ ์ ํ ํญ๋ชฉ์ ๋ณ๊ฒฝ ํ ์ ์์ต๋๋ค.
<body>
<!-- select & option ํ๊ทธ๋ง ์ฌ์ฉ -->
<form action="#" method="post">
<fieldset>
<legend>๊ฐ์ธ ์ ๋ณด ์
๋ ฅ</legend>
<label for="city">์ง์ญ</label>
<select name="city" id="city">
<option value="๊ฐ๋ถ๊ตฌ">๊ฐ๋ถ๊ตฌ</option>
<option value="๊ฐ๋จ๊ตฌ">๊ฐ๋จ๊ตฌ</option>
<option value="์์ด๊ตฌ" selected>์์ด๊ตฌ</option>
<option value="์ค์๊ตฌ">์ค์๊ตฌ</option>
<option value="๋ถ๋น๊ตฌ">๋ถ๋น๊ตฌ</option>
</select>
<input type="submit" value="๋ฑ๋ก">
</fieldset>
</form>
</body>
button ํ๊ทธ
<body>
<form action="#">
<button type="submit">
<img src="facebook.png" alt="ํ์ด์ค๋ถ ๋ฒํผ">
ํ์ด์ค๋ถ์ ๋ฑ๋กํ๊ธฐ
</button>
</form>
</body>
- submit : ํผ์ ์๋ฒ๋ก ์ ์ก
- reset : ์
๋ ฅํ ๋ด์ฉ ์ด๊ธฐํ
- button : ๋ฒํผ ํํ๋ก ๋ง๋ค์ง๋ง ๊ธฐ๋ฅ์ ์์
ํผ ๊ด๋ จ ํ๊ทธ์์ ์ฌ์ฉํ ์ ์๋ ์ถ๊ฐ ์์ฑ
disable ์์ฑ
- ์ํธ์์ฉ ์์๋ฅผ ๋นํ์ฑํ
- input, text, area, select, button ํ๊ทธ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- ํ๊ทธ๊ฐ ๋นํ์ฑํ๋๋ฉด ์
๋ ฅ ์์๋ ํ
์คํธ๋ฅผ ์
๋ ฅ ํ ์ ์๊ณ , ๋ชฉ๋ก ์์๋ ํญ๋ชฉ์ ์ ํํ ์ ์์ผ๋ฉด, ๋ฒํผ ์์๋ ๋ฒํผ์ ํด๋ฆญํ ์ ์์ต๋๋ค.
<body>
<input type="text" disabled>
<button type="button" disabled>๋นํ์ฑ</button>
</body>
readonly ์์ฑ
- ์ฝ๊ธฐ ์ ์ฉ์ผ๋ก ๋ณ๊ฒฝ
<body>
<input type="text" readonly>
<textarea readonly></textarea>
</body>
maxlength ์์ฑ
- ์
๋ ฅํ ์ ์๋ ๊ธ์ ์ ์ ํ
<input type="url" maxlength="4">
<textarea maxlength="4"></textarea>
checked ์์ฑ
- ์์๋ฅผ ์ ํ๋ ์ํ๋ก ํ์
- checkbox ํน์ radio ์์์๋ง ์ฌ์ฉ ๊ฐ๋ฅ
<body>
<form action="#">
<fieldset>
<legend>์ข์ํ๋ ๊ณผ์ผ</legend>
<input type="checkbox" id="banana" name="banana" value="banana">
<label for="banana">banana</label><br>
<input type="checkbox" id="apple" name="apple" value="apple">
<label for="apple">apple</label><br>
<input type="checkbox" id="orange" name="orange" value="orange" checked>
<label for="orange">orange</label><br>
</fieldset>
</form>
</body>
placeholder ์์ฑ
- ์
๋ ฅ ์์์ ์ด๋ค ๊ฐ์ ์
๋ ฅํ๋ฉด ๋๋์ง ํํธ๋ฅผ ์ ๋ ์ฉ๋
<input type="tel" placeholder="์ ํ๋ฒํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.">
required ์์ฑ
- ๋ด์ฉ์ ํผ์ ์
๋ ฅํ ํ submit ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํผ์ ์๋ฒ๋ก ์ ์ก..
์ด ๋ ํ์ ํ๋์ ํ์ํ ๋ด์ฉ์ด ๋ชจ๋ ์ฑ์์ก๋์ง ๊ฒ์ฌํด์ผ ํจ.