'웹 폼’은 사용자가 웹 사이트 또는 어플리케이션 사이의 주요한 상호 작용 지점 중 하나이다. 입력한 데이터는 처리 및 저장을 위해 웹 서버로 전송하거나 클라이언트 측에서 인터페이스를 업데이트 하는 데 사용한다.
이러한 웹 폼의 HTML은 하나 이상의 ‘폼 컨트롤’과 전체 폼을 구성하는데 도움이 되는 추가 요소들로 구성되며 이를 흔히 ‘HTML 폼’이라고 한다.
input
위에서 말하는 폼 컨트롤은 'input'요소로 표현할 수 있으며, 이는 다양한 type 속성을 통해 여러 종류의 입력 필드를 생성할 수 있다.
예를 들어,
<input type=”…”>
(text, number, email, password, date, radio, checkbox, file)
등의 형식으로 작성할 수 있다.
Type
화면에 보여질 입력의 기능을 나타낸다.
예를 들어,
<form action="/" method="GET">
<label for="username">Your name</label>
<input type="text" name="user-name" id="username" />
<label for="usermail">Your email adress</label>
<input type="email" name="user-email" id="useremail" />
<label for="userage">Your age</label>
<input type="number" step="1" name="user-age" id="userage" />
<label for="userpassword">Your password</label>
<input type="password" name="user-password" id="userpassword" />
<label for="birthdate">Your birthdate</label>
<input type="date" id="birthdate" name="birth-date" />
와 같이 다양하게 나타낼 수 있다. (e.g. single line text input, number input, email address input 등 …)
*MDN refrence 참고 가능
select(drop down)
옵션 목록이 길거나 radio 버튼을 대신 하고 싶을 때, 드랍다운 메뉴를 사용할 수 있는 요소이며
예를 들어,
<label for="favorite-color">Your favorite color?</label>
<select id="favorite-color">
<option value="color">Red</option>
<option value="color">Green</option>
<option value="color">Blue</option>
</select>
와 같이 나타낼 수 있으며 이는 여러 옵션 중 하나를 선택할 수 있게 합니다
checkbox
사용자가 여러 옵션 중 하나 이상을 선택할 수 있게 하는 폼 컨트롤이다. HTML에서는 <input> 요소의 type="checkbox" 속성을 사용하여 체크박스를 생성한다.
예를 들어,
<form method="get" action="form-action.html">
<p>색상 선택:</p>
<label><input type="checkbox" name="color" value="blue"> 파란색</label>
<label><input type="checkbox" name="color" value="red"> 빨간색</label>
<p><input type="submit" value="제출"></p>
</form>
와 같이 나타낼 수 있으며, 체크박스는 사용자에게 다양한 선택지를 제공하고 여러 항목을 동시에 선택할 수 있게 하는 유용한 폼 요소이다.
textarea
여러 줄의 텍스트 입력이 가능한 컨트롤을 생성한다.
예를 들어,
<label for="usermessage">Your message</label>
<textarea name="usermessage" id="user-message"></textarea>
와 같이 나타낼 수 있으며 이 요소는 빈 요소가 아니므로 시작 태그와 종료 태그 사이에 기본 텍스트를 포함해야 한다.