Forums

preload user data into form

thewelt 03 Mar, 2014
Hi there,

I'm new into chronoforms V5 and I'm looking for a solution form my problem.
I made a multipage form. In the first page I would like the name of the logged in user to be automaticaly filled in.

How can I doe this ?

tnx for you answer.

Bart Weltens
GreyHead 03 Mar, 2014
Hi Bart,

Please see this FAQ. It is for CFv4 but should work for CFv5 too.

Bob
thewelt 03 Mar, 2014
Thank you Bob,

I already tried it, but it seem not to work.
I'm not sure where (and how) to put the code into the form.

Can you give me some advice ?

tnx for you answer.

Bart
GreyHead 03 Mar, 2014
Hi Bart,

I think you need to add it pretty much as it says in the FAQ. What have you tried?

Bob
thewelt 03 Mar, 2014
First I added follow code into the “setup”tab into the “on load” event just before the HTML(Render Form)-action.
<?php
$user =& JFactory::getUser();
$form->data['naam'] = $user->name;
?>


Then I’m not sure what the next step is as I do not know what to do with “So, if you want to load information about a user from a database table you can use a Custom Code action to put the User ID in the $form->data array and then use that as the 'token' in a DB Record Loader action. In this case you'd use user_id in the Token box:” from the FAQ-step :?
GreyHead 03 Mar, 2014
Hi Bart,

That should give you the name of the current user. Does it?

You only need the DB part if you want to import data from some other table.

Bob
thewelt 03 Mar, 2014
Hi Bob,

No it does not.
I get :
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING in /var/www/vhosts/kbha.be/httpdocs/administrator/components/com_chronoforms5/chronoforms/actions/custom_code/custom_code.php(20) : eval()'d code on line 3

When I go back to the setup tab and open the custom code , it has changed itself to
<?php
$user =& JFactory::getUser();
$form->data[\'naam\'] = $user->name;
?>

(note the \ before and after 'name')
GreyHead 03 Mar, 2014
Answer
HI Bart,

If this is in a Custom Code action (you don't say) then probably your site has Magic Quotes set to on, please try setting them off. You can check the setting on the PHP Info tab in the System Info.

Bob
thewelt 03 Mar, 2014
Hi Bob,

Thank very much.
The Magic_quotes thing did the trick.

Bart
This topic is locked and no more replies can be posted.