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:
And created a new file called holiday_request.php beneath root/models/ directory. Here is the code:
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
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 |
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?
Hi,
Good!
No, use the object.
The data in the object is validated and matches the right format and so on...
Best,
Corretje
Good!
No, use the object.
The data in the object is validated and matches the right format and so on...
Best,
Corretje
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