songining
article thumbnail

<form>ํƒœ๊ทธ๋Š” ์ž…๋ ฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ ์ „์†กํ•œ๋‹ค. 

 

<form action="ํผ์„ ์ „์†กํ•  ์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ" name="ํ…์ŠคํŠธ" method="POST/GET"

 

name ์†์„ฑ์€ ์„œ๋ฒ„๋กœ ์ œ์ถœ๋œ form data๋ฅผ ์ฐธ์กฐํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๊ฑฐ๋‚˜, js์—์„œ ์š”์†Œ๋ฅผ ์ฐธ์กฐํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค. 

ํ•ด๋‹น ํผ์˜ ์ด๋ฆ„์„ ๋ช…์‹œํ•œ๋‹ค. 

method ์†์„ฑ์€ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. ๋ณด์•ˆ์„ ์œ„ํ•ด์„œ๋Š” POST๋ฐฉ์‹์„ ์“ฐ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. 

1. text input 

 

 <input type="text" name="text" id="text" >

 

+) id์™€ name์˜ ์ฐจ์ด?

๋‘˜๋‹ค ํƒœ๊ทธ์™€ ํƒœ๊ทธ๋ฅผ ์‹๋ณ„ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•œ๋‹ค.

id๋Š” ํŽ˜์ด์ง€ ๋‚ด์—์„œ ๊ณ ์œ ํ•œ ๊ฐ’์ด์–ด์•ผ ํ•˜๋ฉฐ css, js, jQuery ์— ์‚ฌ์šฉ๋œ๋‹ค.  

name์€ html์„ ํ†ตํ•ด ์–‘์‹์„ ์ œ์ถœํ•  ๋•Œ PHP์—์„œ ์–‘์‹์„ ์ฒ˜๋ฆฌํ•  ๋–„ ์‚ฌ์šฉ๋œ๋‹ค. 

๋”ฐ๋กœ๋”ฐ๋กœ ๊ณ ์œ ํ•œ ์ ‘๊ทผ์„ ์›ํ• ๋•Œ๋Š” id, ์ค‘๋ณต๋˜๋Š” ๊ฒƒ๋“ค์„ ํ•œ๋ฒˆ์— ์ ‘๊ทผํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š” name์„ ์ด์šฉํ•œ๋‹ค. 

 

+) label ์ถ”๊ฐ€

<label for="patty">What type of protein would you like? </label> 
             <input type="text" name="patty" id="patty"> 

 

 

input์˜ id๊ฐ’๊ณผ label์˜ for๊ฐ’์„ ๋™์ผํ•˜๊ฒŒ ํ•˜๋ฉด ํ•ด๋‹น label์„ ๋ˆŒ๋ €์„ ๋•Œ ํ…์ŠคํŠธํ•„๋“œ๊ฐ€ ํด๋ฆญ๋œ๋‹ค. 

 

2. password input 

 

<input type="password" name="pw" id="pw">

 

type๋งŒ password๋กœ ๋ฐ”๊ฟ”์ฃผ๋ฉด ๋œ๋‹ค. ์œ„์™€ ๊ฐ™์ด ํ…์ŠคํŠธ์•ˆ์˜ ๋‚ด์šฉ์ด ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค. 

 

3. number input 

 

 <label for="amount">How many patties would you like?</label>
          <input type="number" name="amount" id="amount" step="1" >

 

step๊ฐ’์ด ์ดˆ๊ธฐ๊ฐ’์ด๊ณ  ์œ„๋กœ ์˜ฌ๋ฆฌ๋ฉด ์ˆซ์ž๊ฐ€ 1์”ฉ ์ปค์ง„๋‹ค. 

 

4. range input 

   <label for="doneness">How do you want your patty cooked</label>
          <br>
   <span>Rare</span>      
   <input id="doneness" name="doneness" type="range" min="0" max="5" step="0.5">  
   <span>Well-Done</span>

<span>ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•ด ์ค„๋ฐ”๊ฟˆ์„ ํ•˜์ง€ ์•Š๊ณ  ์–‘ ์˜†์— ํ…์ŠคํŠธ๋ฅผ ๋‹ฌ์•„์ฃผ์—ˆ๋‹ค. 

 

5.checkbox input

<span>What toppings would you like?</span>
 <br>
    <input id="lettuce" name="topping" type="checkbox" value="lettuce">
	<label for="lettuce">Lettuce</label>

    <input id="tomato" name="topping" type="checkbox" value="tomato">
    <label for="tomato">Tomato</label>
    
   <input id="cheese" name="topping" type="checkbox" value="cheese">
    <label for="new">Cheese</label>

 

 

6. radio button input 

<span>Would you like to add cheese?</span>
          <br>
<input type="radio" id="yes" name="yse" value="yes">
<label for="yes">Yes</label>

<input type="radio" id="no" name="no" value="no">
<label for="no">No</label>

 

7. dropdown list

<label for="bun">What type of bun would you like?</label>
  <select id="bun" name="bun">
    <option value="sesame" selected="selected">sesame</option>
    <option value="potato">potato</option>
    <option value="nothing">nothing</option>
   </select>

 

select ํƒœ๊ทธ์™€ option ํƒœ๊ทธ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค.

selected ์†์„ฑ๊ฐ’์„ ์ด์šฉํ•˜์—ฌ ๊ธฐ๋ณธ ๊ฐ’์„ ์›ํ•˜๋Š” ์˜ต์…˜์œผ๋กœ ์„ค์ •ํ•ด ๋†“์„ ์ˆ˜ ๋„ ์žˆ๋‹ค. 

 

8. datalist input 

	<label for="sauce">What type of sauce would you like?</label>
       <input list="sauces" id="sauce" name="sauce">
      <datalist id="sauces">
    <option value="ketchup"></option>
    <option value="mayo"></option>
    <option value="chilli"></option>
  
  </datalist>

 

9. submit 

<input type="submit" value="์ „์†ก">

 

๊ฒฐ๊ณผ์ ์œผ๋กœ submit ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด action์— ์ ์–ด ๋‘” ํŒŒ์ผ์ฃผ์†Œ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ „์†ก๋œ๋‹ค.