Kamu Susah Membuat Form HTML ? Nih Saya Bagi Bagi Ilmunya! Simak Baik Baik.
Gulir ke bawah sedikit untuk melihat formulir kami yang dibuat menggunakan HTML. Dan ebih jauh ke bawah
Anda akan melihat kode PHP untuk pengolahannya. Ini digunakan untuk membuat form pengiriman kepada Anda melalui email.
Cara Membuat Form HTML
Copy dan paste kode ini langsung ke halaman web HTML Anda.
01.
<
form
name
=
"htmlform"
method
=
"post"
action
=
"html_form_send.php"
>
02.
<
table
width
=
"450px"
border
=
"0"
>
03.
</
tr
>
04.
<
tr
>
05.
<
td
valign
=
"top"
>
06.
<
label
for
=
"first_name"
>First Name *</
label
>
07.
</
td
>
08.
<
td
valign
=
"top"
>
09.
<
input
type
=
"text"
name
=
"first_name"
maxlength
=
"50"
size
=
"30"
/>
10.
</
td
>
11.
</
tr
>
12.
13.
<
tr
>
14.
<
td
valign
=
"top"
">
15.
<
label
for
=
"last_name"
>Last Name *</
label
>
16.
</
td
>
17.
<
td
valign
=
"top"
>
18.
<
input
type
=
"text"
name
=
"last_name"
maxlength
=
"50"
size
=
"30"
/>
19.
</
td
>
20.
</
tr
>
21.
<
tr
>
22.
<
td
valign
=
"top"
>
23.
<
label
for
=
"email"
>Email Address *</
label
>
24.
</
td
>
25.
<
td
valign
=
"top"
>
26.
<
input
type
=
"text"
name
=
"email"
maxlength
=
"80"
size
=
"30"
/>
27.
</
td
>
28.
29.
</
tr
>
30.
<
tr
>
31.
<
td
valign
=
"top"
>
32.
<
label
for
=
"telephone"
>Telephone Number</
label
>
33.
</
td
>
34.
<
td
valign
=
"top"
>
35.
<
input
type
=
"text"
name
=
"telephone"
maxlength
=
"30"
size
=
"30"
/>
36.
</
td
>
37.
</
tr
>
38.
<
tr
>
39.
<
td
valign
=
"top"
>
40.
<
label
for
=
"comments"
>Comments *</
label
>
41.
</
td
>
42.
<
td
valign
=
"top"
>
43.
<
textarea
name
=
"comments"
maxlength
=
"1000"
cols
=
"25"
rows
=
"6"
></
textarea
>
44.
</
td
>
45.
46.
</
tr
>
47.
<
tr
>
48.
<
td
colspan
=
"2"
style
=
"text-align:center"
>
49.
<
input
type
=
"submit"
value
=
"Kirim"
/>
50.
</
td
>
51.
</
tr
>
52.
</
table
>
53.
</
form
>
Anda juga perlu untuk membuat beberapa baris kode yang menggunakan PHP. Ini digunakan untuk menerima pengiriman form dan mengirimkan email kepada Anda. Ada dua bagian yang harus diubah oleh Anda yaitu email dan subjeknya pada kode-kode di bawah ini.
Simpan file ini sebagai html_form_send.php
01.
<?php
02.
if
(isset(
$_POST
[
'email'
])) {
03.
04.
// Ubah dua baris di bawah ini
05.
$email_to
=
"you@yourdomain.com"
;
06.
07.
$email_subject
=
"website html form submissions"
;
08.
09.
10.
function
died(
$error
) {
11.
// your error code can go here
12.
echo
"We are very sorry, but there were error(s) found with the form you submitted. "
;
13.
echo
"These errors appear below.
14.
15.
";
16.
echo
$error
."
17.
18.
";
19.
echo
"Please go back
and
fix these errors.
20.
21.
";
22.
die
();
23.
}
24.
25.
// validation expected data exists
26.
if
(!isset(
$_POST
[
'first_name'
]) ||
27.
!isset(
$_POST
[
'last_name'
]) ||
28.
!isset(
$_POST
[
'email'
]) ||
29.
!isset(
$_POST
[
'telephone'
]) ||
30.
!isset(
$_POST
[
'comments'
])) {
31.
died(
'We are sorry, but there appears to be a problem with the form you submitted.'
);
32.
}
33.
34.
$first_name
=
$_POST
[
'first_name'
];
// required
35.
$last_name
=
$_POST
[
'last_name'
];
// required
36.
$email_from
=
$_POST
[
'email'
];
// required
37.
$telephone
=
$_POST
[
'telephone'
];
// not required
38.
$comments
=
$_POST
[
'comments'
];
// required
39.
40.
$error_message
=
""
;
41.
$email_exp
=
'/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'
;
42.
if
(!preg_match(
$email_exp
,
$email_from
)) {
43.
$error_message
.= 'The Email Address you entered does not appear to be valid.
44.
';
45.
}
46.
$string_exp
=
"/^[A-Za-z .'-]+$/"
;
47.
if
(!preg_match(
$string_exp
,
$first_name
)) {
48.
$error_message
.= 'The First Name you entered does not appear to be valid.
49.
';
50.
}
51.
if
(!preg_match(
$string_exp
,
$last_name
)) {
52.
$error_message
.= 'The Last Name you entered does not appear to be valid.
53.
';
54.
}
55.
if
(
strlen
(
$comments
) < 2) {
56.
$error_message
.= 'The Comments you entered
do
not appear to be valid.
57.
';
58.
}
59.
if
(
strlen
(
$error_message
) > 0) {
60.
died(
$error_message
);
61.
}
62.
$email_message
=
"Form details below.\n\n"
;
63.
64.
function
clean_string(
$string
) {
65.
$bad
=
array
(
"content-type"
,
"bcc:"
,
"to:"
,
"cc:"
,
"href"
);
66.
return
str_replace
(
$bad
,
""
,
$string
);
67.
}
68.
69.
$email_message
.=
"First Name: "
.clean_string(
$first_name
).
"\n"
;
70.
$email_message
.=
"Last Name: "
.clean_string(
$last_name
).
"\n"
;
71.
$email_message
.=
"Email: "
.clean_string(
$email_from
).
"\n"
;
72.
$email_message
.=
"Telephone: "
.clean_string(
$telephone
).
"\n"
;
73.
$email_message
.=
"Comments: "
.clean_string(
$comments
).
"\n"
;
74.
75.
76.
// create email headers
77.
$headers
=
'From: '
.
$email_from
.
"\r\n"
.
78.
'Reply-To: '
.
$email_from
.
"\r\n"
.
79.
'X-Mailer: PHP/'
. phpversion();
80.
@mail(
$email_to
,
$email_subject
,
$email_message
,
$headers
);
81.
?>
82.
83.
<!-- place your own success html below -->
84.
85.
Terima kasih sudah mengontak kami!
86.
87.
<?php
88.
}
89.
die
();
90.
?>
Untuk menambahkan kolom baru untuk membentuk form Anda, tinggal copy dan paste jenis bidang yang Anda butuhkan dari contoh-contoh di bawah ini.
Kami telah memasukkan beberapa rincian yang berbeda tentang HTML tag Form.
Terima kasih telah mengunjungi Website kami. Bila ada kekurangan mohon maaf. Jangan lupa Share dan tinggalkan Comment Juga Responnya yak guys, untuk info lebih jelas kunjungi link dibawah👍
Sumber: www.ahlitech.com