Feb 25th, 2010, 6:18 AM
Outstanding Ben! Thank you much. I'll give this a shot today!
(Feb 24th, 2010, 10:55 PM)Ben Wrote: Hey Brian,
This was a tough one, I almost gave up. :-)
But here's how you could do it - it's actually not too tricky, but the explanation will take a little while. The only caveat is that you'll need to update one of the functions in the Form Tools core. I'd planned on including the updated function in 2.0.1 beta, but that'll be some time before it's ready - so consider this a pre-release.
Here's how to do it.
(1) Edit your /global/code/submissions.php file and replace the ft_create_blank_submission function with this new code:
PHP Code:<?php
/**
* Creates a new blank submission in the database and returns the unique submission ID. If the
* operation fails for whatever reason (e.g. the form doesn't exist), it just returns the empty
* string.
*
* @param integer $form_id
* @param boolean $is_finalized whether the submission is finalized or not.
*/
function ft_create_blank_submission($form_id, $is_finalized = false)
{
global $g_table_prefix;
if (!ft_check_form_exists($form_id))
return "";
$now = ft_get_current_datetime();
$ip = $_SERVER["REMOTE_ADDR"];
mysql_query("
INSERT INTO {$g_table_prefix}form_{$form_id} (submission_date, last_modified_date, ip_address)
VALUES ('$now', '$now', '$ip')
");
$new_submission_id = mysql_insert_id();
extract(ft_process_hooks("end", compact("form_id", "now", "ip", "new_submission_id"), array()), EXTR_OVERWRITE);
return $new_submission_id;
}
This updated function contains a few updates to pass more information to the hook. I'll explain why that's necessary later.
(2) Add a new field to your form through the Edit Form -> Database tab. Give it these values:
Pass On: (unchecked)
Form Field Name: created_by
Display Text: Created By (Client Account)
Field Size: 20 chars
Data Type: String
Database column: created_by (to edit this field, uncheck the "Auto-generate database column names" checkbox).
(3) Download and install the Hooks Manager module.
After installing it, create a new rule with the following settings:
Status: enabled
Rule Name: Store Who Created Submission
Priority: 50
Hook Type: Code Hook
Code Hook: ft_create_blank_submission, end
PHP Code:
PHP Code:
<?php
if ($form_id == X)
{
$account_id = $_SESSION["ft"]["account"]["account_id"];
$submission_id = $new_submission_id;
$info = array(
"created_by" => $account_id
);
ft_update_submission_info($form_id, $submission_id, $info);
}

