function flexfile_add_fields($event, $object_type, $object)
{
    if (($event == 'create' || $event == 'update') && $object_type == 'object' && $object->getSubtype() == 'file') {
        $form = flexfile_get_file_form($object, $object->file_category);
        if ($form) {
            $data = form_get_data_from_form_submit($form->getGUID());
            foreach ($data as $key => $value) {
                $object->{$key} = $value;
            }
        }
    }
    return $object;
}
 * Handles form submissions.
 *
 */
// Load form model
require_once dirname(dirname(__FILE__)) . "/models/model.php";
global $CONFIG;
// Define context
set_context('form:content');
$form_data_id = get_input('form_data_id', 0);
$form_id = get_input('form_id', 0);
$preview = get_input('preview', 0);
$form = get_entity($form_id);
$title = $form->title;
if ($preview) {
    $body = '<p class="form-description">' . elgg_echo('form:preview_results_description') . '</p>';
    $form_data = form_get_data_from_form_submit($form_id);
    $maps = form_get_maps($form_id);
    if ($maps) {
        foreach ($maps as $map) {
            $field = get_entity($map->field_id);
            $value = isset($form_data[$field->internal_name]) ? $form_data[$field->internal_name] : '';
            $body .= '<p><b>' . $field->title . ' (' . $field->internal_name . ') : ' . $value . '</p>';
        }
    }
} else {
    $result = form_set_data_from_form($form_data_id);
    if ($result->error_status) {
        if ($result->error_reason == 'missing') {
            register_error(elgg_view('form/missing_error', array('missing' => $result->missing)));
        } else {
            if ($result->error_reason == 'save_failed') {
/**
 * Elgg display search form
 * 
 * @package Form
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Kevin Jardine <*****@*****.**>
 * @copyright Radagast Solutions 2008
 * @link http://radagast.biz/
 * 
 * @uses $vars['form_id'] Optionally, the form to add a search definition for
 */
// load form model
require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/models/model.php";
$sd = $vars['search_definition'];
$fd = form_get_data_from_form_submit($sd->form_id);
$form = get_entity($sd->form_id);
$offset = (int) get_input('offset', 0);
$limit = 5;
$search_page_link = '<p><a href="' . $vars['url'] . 'mod/form/search.php?sid=' . $sd->getGUID() . '" >' . elgg_echo('form:return_to_search') . '</a></p>';
//echo $search_page_link;
echo '<div class="contentWrapper">';
echo '<div class="form_listing">';
$result = form_get_data_with_search_conditions($fd, $sd, $limit, $offset);
$count = $result[0];
$entities = $result[1];
if ($entities) {
    if ($form->profile == 1 || $form->profile == 2) {
        echo elgg_view_entity_list($entities, $count, $offset, $limit, false, false);
    } else {
        echo form_view_entity_list($entities, $form, $count, $offset, $limit, false, false);