{"id":491,"date":"2019-09-14T08:08:24","date_gmt":"2019-09-14T08:08:24","guid":{"rendered":"https:\/\/www.webhozz.com\/code\/?p=491"},"modified":"2019-09-14T08:08:26","modified_gmt":"2019-09-14T08:08:26","slug":"php-form-handling","status":"publish","type":"post","link":"https:\/\/www.webhozz.com\/code\/php-form-handling\/","title":{"rendered":"PHP : Form Handling"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Membuat Formulir Kontak Sederhana<\/h5>\n\n\n\n<p>Dalam tutorial ini kita akan membuat formulir kontak HMTL\nsederhana yang memungkinkan pengguna untuk memasukkan komentar dan umpan balik\nmereka kemudian menampilkannya ke browser menggunakan PHP.<\/p>\n\n\n\n<p>Buka editor kode favorit kalian dan buat file PHP baru. Sekarang ketikkan kode berikut dan simpan file ini sebagai &#8220;contact-form.php&#8221; di direktori root proyek kalian.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html lang=&quot;en&quot;&gt;\n&amp;lt;head&gt;\n    &amp;lt;meta charset=&quot;UTF-8&quot;&gt;\n    &amp;lt;title&gt;Contact Form&amp;lt;\/title&gt;\n&amp;lt;\/head&gt;\n&amp;lt;body&gt;\n    &amp;lt;h2&gt;Contact Us&amp;lt;\/h2&gt;\n    &amp;lt;p&gt;Please fill in this form and send us.&amp;lt;\/p&gt;\n    &amp;lt;form action=&quot;process-form.php&quot; method=&quot;post&quot;&gt;\n        &amp;lt;p&gt;\n            &amp;lt;label for=&quot;inputName&quot;&gt;Name:&amp;lt;sup&gt;*&amp;lt;\/sup&gt;&amp;lt;\/label&gt;\n            &amp;lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;inputName&quot;&gt;\n        &amp;lt;\/p&gt;\n        &amp;lt;p&gt;\n            &amp;lt;label for=&quot;inputEmail&quot;&gt;Email:&amp;lt;sup&gt;*&amp;lt;\/sup&gt;&amp;lt;\/label&gt;\n            &amp;lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;inputEmail&quot;&gt;\n        &amp;lt;\/p&gt;\n        &amp;lt;p&gt;\n            &amp;lt;label for=&quot;inputSubject&quot;&gt;Subject:&amp;lt;\/label&gt;\n            &amp;lt;input type=&quot;text&quot; name=&quot;subject&quot; id=&quot;inputSubject&quot;&gt;\n        &amp;lt;\/p&gt;\n        &amp;lt;p&gt;\n            &amp;lt;label for=&quot;inputComment&quot;&gt;Message:&amp;lt;sup&gt;*&amp;lt;\/sup&gt;&amp;lt;\/label&gt;\n            &amp;lt;textarea name=&quot;message&quot; id=&quot;inputComment&quot; rows=&quot;5&quot; cols=&quot;30&quot;&gt;&amp;lt;\/textarea&gt;\n        &amp;lt;\/p&gt;\n        &amp;lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;\n        &amp;lt;input type=&quot;reset&quot; value=&quot;Reset&quot;&gt;\n    &amp;lt;\/form&gt;\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n<\/pre><\/div>\n\n\n<h5 class=\"wp-block-heading\">Penjelasan Kode<\/h5>\n\n\n\n<p>Perhatikan bahwa ada dua atribut di dalam tag <strong><em>&lt;form&gt;<\/em><\/strong>\npembuka:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Atribut <strong><em>action<\/em><\/strong> merujuk kepada file PHP &#8220;<em>process-form.php<\/em>&#8221; yang menerima data yang dimasukkan ke dalam formulir ketika pengguna mengirimkannya dengan menekan tombol kirim.<\/li><li>Atribut <strong><em>method<\/em><\/strong> memberi tahu browser untuk mengirim data formulir melalui <em>metode POST<\/em>.<\/li><\/ul>\n\n\n\n<p>Sisa elemen di dalam formulir adalah kontrol formulir dasar untuk menerima input pengguna.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Mengambil Data Formulir dengan PHP<\/h5>\n\n\n\n<p>Untuk mengakses nilai bidang formulir tertentu, kalian bisa menggunakan variabel superglobal berikut. Variabel-variabel ini tersedia di semua cakupan pada seluruh skrip.<\/p>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th>Superglobal<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$_GET<\/code><\/td><td>Berisi daftar semua nama bidang dan nilai yang dikirim oleh formulir menggunakan metode get (mis. Melalui parameter URL).<\/td><\/tr><tr><td><code>$_POST<\/code><\/td><td>Berisi daftar semua nama bidang dan nilai yang dikirim oleh formulir menggunakan metode posting (data tidak akan terlihat di URL).<\/td><\/tr><tr><td><code>$_REQUEST<\/code><\/td><td>Berisi nilai-nilai dari variabel <strong><em>$_GET <\/em><\/strong>dan <strong><em>$_POST<\/em><\/strong> serta nilai dari variabel superglobal <strong><em>$_COOKIE.<\/em><\/strong><\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>Ketika pengguna mengirimkan formulir kontak di atas dengan\nmengklik tombol kirim, data formulir dikirim ke file &#8220;<em>process-form.php<\/em>&#8221; di server untuk diproses. Ini hanya\nmenangkap informasi yang dikirimkan oleh pengguna dan menampilkannya ke\nbrowser.<\/p>\n\n\n\n<p>Kode PHP file &#8220;<em>process-form.php<\/em>&#8221; akan terlihat seperti ini:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;title&gt;Contact Form&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;h1&gt;Thank You&lt;\/h1&gt;\n    &lt;p&gt;Here is the information you have submitted:&lt;\/p&gt;\n    &lt;ol&gt;\n        &lt;li&gt;&lt;em&gt;Name:&lt;\/em&gt; &lt;?php echo $_POST&#x5B;&quot;name&quot;]?&gt;&lt;\/li&gt;\n        &lt;li&gt;&lt;em&gt;Email:&lt;\/em&gt; &lt;?php echo $_POST&#x5B;&quot;email&quot;]?&gt;&lt;\/li&gt;\n        &lt;li&gt;&lt;em&gt;Subject:&lt;\/em&gt; &lt;?php echo $_POST&#x5B;&quot;subject&quot;]?&gt;&lt;\/li&gt;\n        &lt;li&gt;&lt;em&gt;Message:&lt;\/em&gt; &lt;?php echo $_POST&#x5B;&quot;message&quot;]?&gt;&lt;\/li&gt;\n    &lt;\/ol&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre><\/div>\n\n\n<p>Kode PHP di atas cukup sederhana. Karena data formulir\ndikirim melalui metode posting, kalian dapat mengambil nilai bidang formulir\ntertentu dengan memberikan namanya ke array superglobal <strong><em>$_POST<\/em><\/strong>, dan menampilkan\nsetiap nilai bidang menggunakan pernyataan <strong><em>echo().<\/em><\/strong><\/p>\n\n\n\n<p>Di dunia nyata kalian tidak bisa mempercayai input pengguna;\nkalian harus menerapkan semacam validasi untuk memfilter input pengguna sebelum\nmenggunakannya. Pada bab selanjutnya kalian akan belajar bagaimana membersihkan\ndan memvalidasi data formulir kontak ini dan mengirimkannya melalui email\nmenggunakan PHP.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Membuat Formulir Kontak Sederhana Dalam tutorial ini kita akan membuat formulir kontak HMTL sederhana yang memungkinkan pengguna untuk memasukkan komentar dan umpan balik mereka kemudian<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-491","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Belajar PHP : Form Handling - WebHozz Code<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhozz.com\/code\/php-form-handling\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Belajar PHP : Form Handling - WebHozz Code\" \/>\n<meta property=\"og:description\" content=\"Membuat Formulir Kontak Sederhana Dalam tutorial ini kita akan membuat formulir kontak HMTL sederhana yang memungkinkan pengguna untuk memasukkan komentar dan umpan balik mereka kemudian\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhozz.com\/code\/php-form-handling\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHozz Code\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-14T08:08:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-09-14T08:08:26+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"headline\":\"PHP : Form Handling\",\"datePublished\":\"2019-09-14T08:08:24+00:00\",\"dateModified\":\"2019-09-14T08:08:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/\"},\"wordCount\":318,\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/\",\"name\":\"Belajar PHP : Form Handling - WebHozz Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\"},\"datePublished\":\"2019-09-14T08:08:24+00:00\",\"dateModified\":\"2019-09-14T08:08:26+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/php-form-handling\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP : Form Handling\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#website\",\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/\",\"name\":\"WebHozz Code\",\"description\":\"Tutorial Web &amp; Pemrograman Indonesia\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/#\\\/schema\\\/person\\\/3b2b79dc317236b0dde4b1fda37263e1\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/www.webhozz.com\\\/code\\\/author\\\/dody\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Belajar PHP : Form Handling - WebHozz Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhozz.com\/code\/php-form-handling\/","og_locale":"en_US","og_type":"article","og_title":"Belajar PHP : Form Handling - WebHozz Code","og_description":"Membuat Formulir Kontak Sederhana Dalam tutorial ini kita akan membuat formulir kontak HMTL sederhana yang memungkinkan pengguna untuk memasukkan komentar dan umpan balik mereka kemudian","og_url":"https:\/\/www.webhozz.com\/code\/php-form-handling\/","og_site_name":"WebHozz Code","article_published_time":"2019-09-14T08:08:24+00:00","article_modified_time":"2019-09-14T08:08:26+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webhozz.com\/code\/php-form-handling\/#article","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/php-form-handling\/"},"author":{"name":"admin","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"headline":"PHP : Form Handling","datePublished":"2019-09-14T08:08:24+00:00","dateModified":"2019-09-14T08:08:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhozz.com\/code\/php-form-handling\/"},"wordCount":318,"articleSection":["PHP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.webhozz.com\/code\/php-form-handling\/","url":"https:\/\/www.webhozz.com\/code\/php-form-handling\/","name":"Belajar PHP : Form Handling - WebHozz Code","isPartOf":{"@id":"https:\/\/www.webhozz.com\/code\/#website"},"datePublished":"2019-09-14T08:08:24+00:00","dateModified":"2019-09-14T08:08:26+00:00","author":{"@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1"},"breadcrumb":{"@id":"https:\/\/www.webhozz.com\/code\/php-form-handling\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhozz.com\/code\/php-form-handling\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhozz.com\/code\/php-form-handling\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhozz.com\/code\/"},{"@type":"ListItem","position":2,"name":"PHP : Form Handling"}]},{"@type":"WebSite","@id":"https:\/\/www.webhozz.com\/code\/#website","url":"https:\/\/www.webhozz.com\/code\/","name":"WebHozz Code","description":"Tutorial Web &amp; Pemrograman Indonesia","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhozz.com\/code\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.webhozz.com\/code\/#\/schema\/person\/3b2b79dc317236b0dde4b1fda37263e1","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f222cb0ed38f2100d666bb262fd38d4f0d8e5673698208e40ff83118f10a4e8e?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.webhozz.com\/code\/author\/dody\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":1,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":492,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/posts\/491\/revisions\/492"}],"wp:attachment":[{"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhozz.com\/code\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}