Form Block - Fill fields with user information automatically

Permalink 1 user found helpful
Dear community,

I created a form and would like to insert the information of the user who is currently logged in. Where and how can I do this?

Thanks a lot and kind regards,

Lovic

Lovic
 
Cahueya replied on at Permalink Reply
You do:

$u = new User;
$username = $u->getUserName()

and now $username contains your current logged in user.

You will find lots of useful snippets here:
https://www.webli.us/cheatsheet/doku.php...
Lovic replied on at Permalink Reply
Lovic
Hello Cahueya,

thanks for your reply. I have been able to use the user info object to display infos in the header. I just dont know how to bring these information into the form block automatically, when a user navigates to the respective subpage. Didnt find a snippet in your link that could help me finding a solution.

Kind regards,

Lovic
Lovic replied on at Permalink Reply
Lovic
Hi,

I have managed to include a script which gets the user infos from the userinfo object and the page ID of the page on which users can send data using the form.

How do I transmit the values into the fields? I know the ID of the fields and the names, but not how to address them.

Thanks a lot,

Lovic
Lovic replied on at Permalink Reply
Lovic
Hi,

for all who may help this:

<?php
use Concrete\Core\User\User;

$u = new User();
$ui = $u->getUserInfoObject();
?>

<script>
document.getElementById("NameofField").placeholder = "<?php echo $ui->getAttribute('attributename')?>";
</script>

Kind regards,

Lovic