Form Model
Forms are comprised of custom fields, configured at Publish > Forms, and allow the administrator to easily build complex forms without any HTML or programming knowledge. This model gives you the power to create, update, retrieve, and delete forms. Also, record and retrieve form submissions.
Initialization
$this->load->model('forms/form_model');
Method Reference
int new_form (string $title , string $url_path , string $text , string $button_text , string $redirect [, string $email = '' [, array $privileges = array() [, string $template = 'form.thtml']]])
Create a new form.
int update_form (int $form_id , string $title , string $url_path , string $text , string $button_text , string $redirect [, string $email = '' [, array $privileges = array() [, string $template = 'form.thtml']]])
Update an existing form.
boolean delete_form (int $form_id)
Delete a form.
int get_form_id (string $url_path)
Get a form ID from a URL path. Used in the forms controller.
array get_form (int $form_id)
Retrieve a form based on its ID, in the same format as get_forms().
array get_forms ( [array $filters = array()])
Retrieve a form or forms in an array based on optional filters.
Possible Filters:
- int id
- string title
Each form array has the following data:
- id
- link_id - Corresponding with the Link model
- table_name - The database table holding submissions
- custom_field_group_id
- title
- text
- admin_link
- url
- url_path
- email - Email to which results are sent automatically (may be empty)
- button_text - The submission button's text
- redirect - URL path to redirect to after submission
- privileges - An array of member groups that can access this form
- num_responses - The total number of responses
- template - The template used to display the form
int new_response (int $form_id [, int $user_id = FALSE [, array $custom_fields = array()]])
Insert a new response into the database for a particular form. The $custom_fields array is generated by the Form Builder's post_to_array (documentation).
boolean delete_response (int $form_id , int $response_id)
Delete a response.
array get_response (int $form_id , int $response_id)
Retrieve a single response, in the same format as get_responses().
array get_responses ( [array $filters = array()])
Retrieve a response or multiple responses based on optional filters.
Possible Filters:
- int id
- string title
- int form_id - Required
- int limit
- int response_id
- string start_date
- string end_date
- string username
Each response array has the following data:
- id
- form_id
- submission_date
- user_id
- All field data is passed with the name of the field as the key in the array
- If the form was submitted by a logged in member: member_username, member_email, member_first_name, member_last_name