{"id":863,"date":"2018-05-16T06:02:20","date_gmt":"2018-05-15T23:02:20","guid":{"rendered":"https:\/\/www.bagi2info.com\/?p=863"},"modified":"2022-09-11T14:12:44","modified_gmt":"2022-09-11T07:12:44","slug":"membuat-custom-form-feedback-di-joomla","status":"publish","type":"post","link":"https:\/\/www.bagi2info.com\/en\/php-creating-custom-feedback-forms-in-joomla\/","title":{"rendered":"PHP: Creating Custom Feedback Forms in Joomla"},"content":{"rendered":"\r\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2018\/05\/2018-05-16_09h02_26.png\"><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"264\" class=\"wp-image-1182\" src=\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2018\/05\/2018-05-16_09h02_26.png\" alt=\"Form sample joomla custom\" srcset=\"https:\/\/www.bagi2info.com\/wp-content\/uploads\/2018\/05\/2018-05-16_09h02_26.png 488w, https:\/\/www.bagi2info.com\/wp-content\/uploads\/2018\/05\/2018-05-16_09h02_26-300x162.png 300w\" sizes=\"auto, (max-width: 488px) 100vw, 488px\" \/><\/a><\/figure>\r\n\r\n\r\n\r\n\r\nThere are various components provided by Joomla CMS to create forms, one of which is Fabric, but sometimes we also want to create our own custom forms for our own reasons, the form will be made from an article which then the final action is handled by the php file that we created.\r\n\r\n\r\n\r\n\r\n\r\nHere&#8217;s an easy way to create a custom feedback form in Joomla:\r\n\r\n\r\n\r\n\r\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.bagi2info.com\/en\/php-creating-custom-feedback-forms-in-joomla\/#1_Create_table_di_mysql\" >1. Create table di mysql<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.bagi2info.com\/en\/php-creating-custom-feedback-forms-in-joomla\/#2_Create_a_new_article_with_the_following_html\" >2. Create a new article with the following html<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.bagi2info.com\/en\/php-creating-custom-feedback-forms-in-joomla\/#3_Create_a_new_file_with_the_name_insertfeedbackphp_and_place_it_in_the_root_of_the_joomla_instance\" >3. Create a new file with the name insertfeedback.php and place it in the root of the joomla instance<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Create_table_di_mysql\"><\/span>1. Create table di mysql<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n\r\nRun the following SQL query command after connecting the mysql database, the command below to create a feedback table, the storage of our feedback form.\r\n\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code class=\"language-sql line-numbers\" lang=\"sql\">CREATE TABLE `feedback` (\r\n `id` int(11) NOT NULL,\r\n `title` varchar(255),\r\n `description` text,\r\n `email` varchar(255)\r\n)<\/code><\/pre>\r\n\r\n\r\n\r\n<div class=\"wp-block-spacer\" style=\"height: 100px;\" aria-hidden=\"true\">&nbsp;<\/div>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Create_a_new_article_with_the_following_html\"><\/span>2. Create a new article with the following html<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n\r\nThe command below is a regular html command to create a form display, such as headers, input fields title, description, and email.\r\n\r\n\r\n\r\n\r\n\r\nThe action attribute in the form tag can be adjusted according to the location of the php file that we created.\r\n\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code class=\"language-markup line-numbers\" lang=\"markup\">&lt;form action=\"..\/insertfeedback.php\" method=\"POST\"&gt;\r\n  &lt;h2&gt;Submit your suggestions&lt;\/h2&gt;\r\n  &lt;table&gt;\r\n    &lt;tbody&gt;\r\n      &lt;tr&gt;\r\n        &lt;td&gt;Title&lt;\/td&gt;\r\n        &lt;td&gt;\r\n          &lt;input id=\"title\" style=\"width: 300px\" name=\"title\" type=\"text\" \/&gt;\r\n        &lt;\/td&gt;\r\n      &lt;\/tr&gt;\r\n      &lt;tr&gt;\r\n        &lt;td&gt;Description&lt;\/td&gt;\r\n        &lt;td&gt;\r\n          &lt;textarea\r\n            id=\"description\"\r\n            style=\"width: 350px\"\r\n            name=\"description\"\r\n            rows=\"5\"\r\n          &gt;&lt;\/textarea&gt;\r\n        &lt;\/td&gt;\r\n      &lt;\/tr&gt;\r\n      &lt;tr&gt;\r\n        &lt;td&gt;Email&lt;\/td&gt;\r\n        &lt;td&gt;\r\n          &lt;input id=\"email\" style=\"width: 300px\" name=\"email\" type=\"text\" \/&gt;\r\n        &lt;\/td&gt;\r\n      &lt;\/tr&gt;\r\n      &lt;tr&gt;\r\n        &lt;td colspan=\"2\"&gt;\r\n          &lt;input name=\"submit\" type=\"submit\" value=\"Submit\" \/&gt;\r\n        &lt;\/td&gt;\r\n      &lt;\/tr&gt;\r\n    &lt;\/tbody&gt;\r\n  &lt;\/table&gt;\r\n&lt;\/form&gt;\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n<div class=\"wp-block-spacer\" style=\"height: 100px;\" aria-hidden=\"true\">&nbsp;<\/div>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Create_a_new_file_with_the_name_insertfeedbackphp_and_place_it_in_the_root_of_the_joomla_instance\"><\/span>3. Create a new file with the name insertfeedback.php and place it in the root of the joomla instance<span class=\"ez-toc-section-end\"><\/span><\/h3>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code class=\"language-php line-numbers\" lang=\"php\">&lt;?php\r\n\r\nini_set('display_errors', true);\r\n\/\/error_reporting(E_ALL);\r\ndefine('_JEXEC', 1);\r\ndefine('JPATH_BASE', dirname(__FILE__));\r\ndefine('DS', DIRECTORY_SEPARATOR);\r\n\r\nrequire_once(JPATH_BASE . DS . 'includes' . DS . 'defines.php');\r\nrequire_once(JPATH_BASE . DS . 'includes' . DS . 'framework.php');\r\n\r\n\/*To use Joomla's database class*\/\r\nrequire_once(JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'platform.php');\r\n\r\n\/\/ untuk joomla lama bisa mengganti file dengan factory.php\r\n\/\/require_once (JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'platform.php');\r\n\r\n\r\n$db = JFactory::getDBO();\r\n$session = JFactory::getSession();\r\n$title = JRequest::getVar(\"title\");\r\n$description = JRequest::getVar(\"description\");\r\n$email = JRequest::getVar(\"email\");\r\n\r\n$sql = \"INSERT INTO feedback (title, description, email)\r\nVALUES (\" . $db-&gt;quote($title) . \", \" . $db-&gt;quote($description) . \", \" . $db-&gt;quote($email) . \")\";\r\n\r\n$db-&gt;setQuery($sql);\r\n$db-&gt;query();\r\n\r\n\/\/ print message&nbsp;\r\necho \"Your feedback has been submitted\";\r\n\/\/ or refers to other page\/article\r\n\/\/header('Location: http:\/\/www.google.com');\r\n\/\/exit;\r\n<\/code><\/pre>\r\n\r\n\r\n\r\n\r\nThe above command will handle the input from the form and save it into the feedback table that we created.\r\n\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code class=\"\">$db = JFactory::getDBO();  \/\/ membuat koneksi ke database<\/code><\/pre>\r\n\r\n\r\n\r\n\r\n","protected":false},"excerpt":{"rendered":"<p>There are various components provided by Joomla CMS to create forms, one of which is Fabric, but sometimes we also want to create our own custom forms for our own reasons, the form will&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1182,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[71,82,62,7],"class_list":["post-863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-komputer","tag-joomla","tag-mysql","tag-php","tag-sql"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/comments?post=863"}],"version-history":[{"count":0,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/posts\/863\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/media\/1182"}],"wp:attachment":[{"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/media?parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/categories?post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bagi2info.com\/en\/wp-json\/wp\/v2\/tags?post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}