Storing Current User ID in hidden field before saving
While user is trying to submit publicForm, I need to save the current logged in user ID in some hidden field. I created some field named 'user_id', and made it hidden using Input Helper. Also, Created some 'Pre-Save Helper' for the pod, which does: <?php
global $current_user; $current_user_id = $current_user->ID; $columns['user_id']['value'] = $current_user_id; ?>
But, I always get NULL in the table in DB for that field. So, What would be the problem ?
edited Feb 4 at 6:26
3 Answers
You need to make a call to wp_get_current_user(); after you declare $current_user.
OK, I think I should use: $current_user->data->ID Instead of: $current_user->ID
to get the ID, But still get NULL in DB !
edited Feb 5 at 7:52
I did some more checking. I have this on one of my sites.
I use this code to set the user's id, and hide the field using CSS.
<?php global $current_user; ?>
<select class="form pick1 <?php echo $name; ?>" disabled>
<option value="">-- Select one --</option>
<?php
if (!empty($value)) {
foreach ($value as $key => $val) {
$selected = ($val['id'] === $current_user->ID) ? 'selected' : ''; ?>
<option value="<?php echo $val['id']; ?>"<?php echo $selected; ?>><?php echo $val['name']; ?></option>
<?php
}
}
?>
</select>


