form 요소: action, method, enctype
action, method, enctype을 사용해 form 요소를 설정합니다.
form 요소: action, method, enctype은(는) CoddyKit의 무료 HTML Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 HTML Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. HTML Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
폼이란 무엇인가요?
HTML 폼은 사용자가 서버에 데이터를 제출하는 기본 방법입니다:
- 로그인 및 회원 가입
- 검색어
- 결제 및 주문
- 연락 및 피드백
모든 폼은 <form> 요소로 시작합니다.
form 요소
<form> 요소는 모든 폼 컨트롤을 감쌉니다:
<form action="/submit" method="post">
<!-- form controls go here -->
<button type="submit">Send</button>
</form>
<!-- When the user submits, the browser sends the form data
to the URL specified in action using the method specified -->action 속성
action 속성은 폼 데이터가 전송될 위치를 지정합니다:
<form action="/api/login">...</form> <!-- relative path -->
<form action="https://api.example.com/form">...</form> <!-- absolute -->
<form action="">...</form> <!-- current URL (empty) -->
<form>...</form> <!-- no action = current URL -->method 속성
method 속성은 데이터를 전송하는 방법을 제어합니다:
<form method="get">...</form>
<!-- GET: appends data to URL as query string
example.com/search?q=html&sort=date
Used for: search forms, filters, bookmarkable results -->
<form method="post">...</form>
<!-- POST: sends data in the request body
Data is not visible in the URL
Used for: login, registration, file uploads, sensitive data -->GET과 POST 비교
GET과 POST에는 서로 다른 특징이 있습니다:
- GET — URL에 데이터를 포함합니다(길이 제한 있음), 북마크할 수 있고 캐시되며 멱등적입니다
- POST — 본문에 데이터를 포함합니다(크기 제한 없음), 북마크할 수 없고 캐시되지 않으며 멱등적이지 않습니다
일반적인 기준은 다음과 같습니다. 제출해도 서버 상태가 바뀌지 않으면 GET을 사용하고, 바뀌면 POST를 사용합니다.
enctype 속성
enctype 속성은 POST 요청을 위해 폼 데이터를 인코딩하는 방법을 제어합니다:
<!-- Default: URL-encoded (text/form fields) -->
<form method="post" enctype="application/x-www-form-urlencoded">
<!-- For file uploads: multipart -->
<form method="post" enctype="multipart/form-data">
<input type="file" name="avatar">
</form>
<!-- Plain text (rare): -->
<form method="post" enctype="text/plain">novalidate 속성
novalidate 속성은 브라우저의 기본 제공 유효성 검사를 비활성화합니다:
<form action="/submit" method="post" novalidate>
<!-- Validation handled by JavaScript instead -->
<input type="email" name="email">
<button type="submit">Submit</button>
</form>폼의 target 속성
target 속성은 응답을 표시할 위치를 제어합니다:
<form action="/search" target="_blank">
<!-- Response opens in a new tab -->
</form>
<!-- Values: _blank, _self, _parent, _top, or a frame name -->
<!-- Rarely used — most forms stay on the same page or use AJAX -->폼의 autocomplete
autocomplete 속성은 브라우저 자동 완성을 제어합니다:
<!-- Off: disable autofill for the entire form -->
<form autocomplete="off">
<!-- On (default): allow autofill -->
<form autocomplete="on">
<!-- Better: control at the field level:
<input type="email" autocomplete="email">
<input type="current-password" autocomplete="current-password">
-->JavaScript로 폼 제출하기
기본 제출을 막고 JavaScript로 처리합니다:
<form id="contact-form" action="/contact" method="post">
<input type="text" name="name">
<button type="submit">Send</button>
</form>
<script>
document.getElementById('contact-form').addEventListener('submit', async (e) => {
e.preventDefault(); // stop normal browser submission
const data = new FormData(e.target);
const res = await fetch('/contact', { method: 'POST', body: data });
// handle response...
});
</script>action과 method 함께 사용하기
올바른 action과 method를 사용한 완전한 폼 예제입니다:
<form action="/api/newsletter" method="post">
<label for="email">Email address</label>
<input type="email" id="email" name="email" required>
<button type="submit">Subscribe</button>
</form>
<!-- POST because: creating a subscription = server state change -->빠른 확인
파일을 업로드할 때 어떤 폼 method를 사용해야 하나요?
복습: form 요소
폼 요소의 핵심 내용입니다:
action— 폼 데이터를 받는 URLmethod="get"— URL에 데이터를 포함합니다(검색, 필터)method="post"— 본문에 데이터를 포함합니다(민감한 데이터, 상태 변경)enctype="multipart/form-data"— 파일 업로드에 필요합니다novalidate— 브라우저 유효성 검사를 비활성화합니다
자주 묻는 질문
“form 요소: action, method, enctype” 강의는 무료인가요?
네 — “form 요소: action, method, enctype” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 HTML Academy 강의 전체를 잠금 해제할 수 있습니다. HTML Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“form 요소: action, method, enctype”에서 뭘 배우나요?
action, method, enctype을 사용해 form 요소를 설정합니다. 브라우저에서 직접 실행하는 실습 코드로 HTML Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
HTML Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 HTML Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“form 요소: action, method, enctype” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 HTML Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 HTML Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- form 요소: action, method, enctype
- 입력 타입: text, password, email, number, tel
- label 요소와 접근성
- button 요소: submit, reset, button