There is a way to find out the UID of the user who is editing the form ?

My form have a hidden field with the token: %profile[profile_fullname]

So...I know who submited the form, but after that another person edit the same form, and the field above remains with the first user who created the form...

To workaround this situation, I have created an dynamic_field with the following:

$result = db_query("SELECT users.uid AS uid, profile_values_profile_fullname.value AS profile_values_profile_fullname_value
 FROM users users LEFT JOIN profile_values profile_values_profile_fullname ON users.uid = profile_values_profile_fullname.uid AND profile_values_profile_fullname.fid = '2' ORDER BY profile_values_profile_fullname_value ASC");
$arr = array();
while ($record = db_fetch_array($result)) {
  $arr[check_plain($record['profile_values_profile_fullname_value'])] = check_plain($record['profile_values_profile_fullname_value']);
}
return $arr;

This is returning obviously an select field with all site users name.

Certainly this is not the best way, I need to get this user automatically.

Please, someone could help me ?

Comments

rsacchi’s picture

In the situation above when a user is editing the form, he needs to pick up their username from the list generated from dynamic_field...

quicksketch’s picture

I would suggest using the 3.x version and using the hook_webform_select_options() hook to provide a dynamic select list with $uid => $username keys. Then set the default value of the form to %uid in the webform setting. However this still probably won't automatically-update when users update the submission. You may need to use hook_form_alter() in a custom module to get such functionality.

rsacchi’s picture

Quicksketch thanks again for your support and patience.

I'am completly disoriented, could you please gime me the ideia on how to do that?

As I know I need to create a module with some code, like:

<?php
/**
* Implementation of hook_form_alter().
*/
function custom_form_alter(&$form, &$form_state, $form_id) {
  // Only affect webform client forms.
  if (strpos($form_id, 'webform_client_form_') === 0) {
    $form['#submit'][] = 'custom_webform_client_form_submit';
  }
}

/**
* Submit callback for webform_client_form.
*/
function custom_webform_client_form_submit($form, &$form_state) {
  if ($form_state['values']['xxxx']['xxxx']) {
    $uid = $form_state['values']['submitted']['uid'];
    db_query('UPDATE {webform_submissions} SET uid = %d WHERE sid = %d', array($uid, $sid));
  }
}
?>

And then how pass it to the webform module ?

quicksketch’s picture

Status: Active » Closed (fixed)

I don't provide support on how to write custom code in the Webform queue. If you find a solution feel free to post it here for others.