Pada artikel ini, kita akan melihat cara mengirimkan formulir tanpa mengklik tombol kirim, bersama dengan memahami berbagai cara untuk menyelesaikan tugas ini melalui implementasi
Formulir dapat dikirimkan tanpa menggunakan tombol kirim dengan menerapkan atribut acara tertentu atau dengan mengklik tautan. Tugas ini dapat dilakukan dengan menggunakan atribut acara OnClick atau dengan menggunakan formulir. kirim () metode dalam Javascript
Approach: The form.submit() method in JavaScript can be utilized to submit a given form. It is similar to activating the form’s submit , but not identical. We will add an “ title” eventlistener to the element on which after clicking that element will lead to the submission of the form. Using the getElementById method the required elements can be targeted and once the element is clicked, the “submit” function is triggered and the form is submitted. The HTML elements used to submit the form can be heading tag, paragraph tag, image tag, and many more.HTMLFormElement.requestSubmit() is also an alternative method to submit the form which requests to submit the form using a specific submit button.
Contoh 1. Contoh ini menggambarkan cara mengirimkan formulir tanpa tombol kirim dan menyimpan data dalam database menggunakan phpMyAdmin.
Note: with attribute type=”submit” will not be submitted with the form while using this method.
indeks. php
<!DOCTYPE html>
<html>
_
<head>
<<0<1<0>
<4head>
_
<<9>
<html3 html4html5html6>
html8html9
<4html3>
<>_6>
html8>9
<4>6>
< 6 7html5 9
<0<1html5<3
<0<5html5<7>
html8<head1>
head3head4
html8<4head1>
________2______8<>1>2>1>
________2______8<>7 >8html5 0
1 2html5 0
1 6html5 8 9
html8<>1 9
________2______8<<6 <7html5________1______9>
head3<02
html8<4<6<06
<4 6>
<<_13>
html8<16
head_3<18
head_3<20
head3<22
html8<24
<4<13>
<4<9>
<4html>
membentuk. php. Kode ini akan membantu kita untuk menghubungkan PHP dengan database dan menyimpan data yang dikirimkan oleh pengguna
membentuk. php
<_35
<36<37 <38<39<40<41<40<43<40________1______45<_46
<36<48<49<37<51
<52<53 <54<55
<_36<24
<_36<59<60
<_52<53 <63<55
<_36<24
<36<68 html5<70<71<72<73
<36<75 html5<77<55
<36<80<37<40<75<46
<_85
Explanation: Here, we need to add the data filled in the form to the database without using submit button. For this, we need to trigger submit() function using HTML element. Using the getElementById() method, we have targeted the required form to be submitted. As soon as HTML is clicked submit() is executed and data is stored in the database. In the above example, we have used the tag to trigger submit function.
Keluaran
Teks yang diketik akan disimpan di database setelah mengklik elemen HTML seperti yang ditampilkan di gif
Example 2: This example describes how to use an image to submit the form. Here, we have used tag to trigger submit() function. Here, we will use the form.php file to store data submitted by the user.
indeks. php
<html>
<36<head>
<52<<0<96<0>
<36<4head>
<_36<<9>
< 6 7html5 9 <1html5<3 <5html5<7>
html8________1__3_______7 >8html5<72 2html5<72 9
________2______8<html32 html33html5html35>
html37<html39 html40html5html42 html43html5html45 html46________2______5html48 ______9__
________2______8<4html32>
<4 6>
<<_13>
html_63
html8<20
html8<22
<24
<4<13>
<36<4<9>
<4html>
Penjelasan. Di kedua contoh di atas, segera setelah elemen HTML diklik, peristiwa ' title' dipicu oleh elemen penargetan menggunakan metode getElementById(). Kemudian bentuk. fungsi submit() dijalankan untuk mengirimkan formulir