Insert form data into my custom table

Permalink Browser Info Environment
Hello
I'm trying to insert the form data to my custom table. So far I've tried to create an event to do so. So on config/site_events.php, I've added the below code:
Events::extend('on_formidable_submit', 'HolidayRequest', 'formidable_submission', 'models/holiday_request.php');

And created a new file called holiday_request.php beneath root/models/ directory. Here is the code:
<?php   defined('C5_EXECUTE') or die(_("Access Denied."));
class HolidayRequest extends Object {
   public function formidable_submission() {
      $db = Loader::db();
      $db->query("INSERT INTO spvHolidayRequest (hrName, hrDepartment, hrManager, hrLeaveType, hrFromDate, hrToDate, hrTotalDays, hrApproval, hrComments, hrDateRequested) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array('hrName' => '', 'hrDepartment' => '', 'hrManager' => '', 'hrLeaveType' => '', 'hrFromDate' => '', 'hrToDate' => '', 'hrTotalDays' => '', 'hrApproval' => 'Pending', 'hrComments' => '', 'hrDateRequested' => date('Y-m-d')));
   }
}


I know the insert query array is blank. But I'm not sure how to get the form data here. Also the event not firing while submitting the form. Am I doing anything wrong?

Please help me. Its very urgent.

Thanks

Type: Discussion
Status: In Progress
ronyDdeveloper
View Replies:
DeWebmakers replied on at Permalink Reply
DeWebmakers
Hi,

Your code seems to be fine...
Use the "Event Tester":https://www.concrete5.org/marketplace/addons/event-tester/...

In your method you should get $ff which is the Formidable Object.
The result should be in there: $ff->results

Best,

Corretje
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
Thanks for your quick reply. The event is now firing. I'm using $_REQUSET to get the form field values. Is it good practice? or shall I must use the object?
DeWebmakers replied on at Permalink Reply
DeWebmakers
Hi,

Good!

No, use the object.
The data in the object is validated and matches the right format and so on...

Best,

Corretje

concrete5 Environment Information

# concrete5 Version
5.6.3.4

# concrete5 Packages
Breadcrumbs (2.0), Contact Directory (1.4), Document Library (1.6.6), Extended Search (1.0), Formidable (2.1.8), Local Weather (2.3), Pro Blog (12.4.4), Pro Events (11.5.0), Project Library Management (1.0.3), Simple Image Gallery (1.1.3), SPV Employee Tools (0.9.4).

# concrete5 Overrides
blocks/autonav, blocks/search, blocks/formidable, blocks/document_library, blocks/page_list, elements/profile, helpers/form, languages/it_IT, languages/ar, languages/tr_TR, languages/es_ES, languages/sl_SI, languages/es_AR, languages/fa_IR, languages/sv_SE, languages/sk_SK, languages/pt_PT, languages/fi_FI, languages/es_PE, languages/nl_NL, languages/de_DE, languages/fr_FR, languages/zh_TW, languages/cs_CZ, languages/ro_RO, languages/el_GR, languages/he_IL, languages/vi_VN, languages/ru_RU, languages/es_MX, languages/ja_JP, languages/nb_NO, languages/zh_CN, languages/da_DK, models/login_user.php, models/holiday_request.php, single_pages/login.php, single_pages/page_forbidden.php, single_pages/members.php, single_pages/register.php, single_pages/page_not_found.php, single_pages/profile, themes/SPVIntranetTheme

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - Off
Full Page Caching - Off

# Server Software
Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/1.0.1e-fips mod_bwlimited/1.4

# Server API
cgi

# PHP Version
5.2.17

# PHP Extensions
bcmath, calendar, cgi, ctype, curl, date, dom, filter, ftp, gd, hash, iconv, imap, ionCube Loader, json, libxml, mbstring, mcrypt, mysql, mysqli, openssl, pcre, PDO, pdo_mysql, pdo_sqlite, posix, Reflection, session, SimpleXML, sockets, SPL, SQLite, standard, tokenizer, xml, xmlreader, xmlwriter, yaml, zip, zlib.

# PHP Settings
max_execution_time - 2000
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 1200
max_input_vars - 1000
memory_limit - 2048M
post_max_size - 200M
safe_mode - Off
safe_mode_exec_dir - /usr/local/php/bin
safe_mode_gid - Off
safe_mode_include_dir - <i>no value</i>
sql.safe_mode - Off
upload_max_filesize - 200M
mysql.max_links - Unlimited
mysql.max_persistent - Unlimited
mysqli.max_links - Unlimited
pcre.backtrack_limit - 100000
pcre.recursion_limit - 100000
session.cache_limiter - nocache
session.gc_maxlifetime - 7200
safe_mode_allowed_env_vars - PHP_
safe_mode_protected_env_vars - LD_LIBRARY_PATH

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.1; rv:49.0) Gecko/20100101 Firefox/49.0

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.