Proflle plugin and loss of user data

austega 29 Sep, 2010
Hi,

I have created an Add_ResearchInterest form that adds information to a data table and sends two emails - one to the user and one to admin. The form is restricted to logged in registered users and I use
<?php
if ( !$mainframe->isSite() ) { return; }
$user =& JFactory::getUser();
?>

<input type='hidden' name='username' value='<?php echo $user->username; ?>' />
<input type='hidden' name='email' value='<?php echo $user->email; ?>' />
<input type='hidden' name='name' value='<?php echo $user->name; ?>' />
<input type='hidden' name='user_id' value='<?php echo $user->id; ?>' />

in the form html to access the user info needed. All works well.

I then cloned this form to be Edit_ResearchInterest, changed its title and added in
<input type="hidden" name="cf_id" />
to the form html, and then applied and enabled the Profile plugin with cf_id as both primary key and record identifier, and editable set to yes.

This form displays the appropriate records when &cf_id=x is added to the form URL. It also updates the record properly on Submit. However the emails no longer work as they do not find the {email}, {name} etc values for the logged in user.

The debug shows:
   1. Form passed first SPAM check OK
   2. Form passed the submissions limit (if enabled) OK
   3. Form passed the Image verification (if enabled) OK
   4. Form passed the server side validation (if enabled) OK
   5. $_POST Array: Array ( [username] => [email] => [name] => [user_id] => [cf_id] => 7 [rsch_name] => BATTY [location] => Dumfries SCOTLAND [period] => 1600- [notes] => Other [submit] => Submit [0939b1ad173084ac3a72d893c71e8877] => 1 [1cf1] => 3c70915a33a7ea7ec118794128ccd776 [chronoformname] => Edit_ResearchInterest )
   6. $_FILES Array: Array ( )
   7. Form passed the plugins step (if enabled) OK
   8. An email has been SENT successfully from (SAG Website)webmaster@sag.org.au to webmaster@austega.com
   9. An email has been SENT successfully from (SAG Website)webmaster@sag.org.au to
  10. Debug End


My guess is that the Profile Plugin is in effect overwriting the form html code that gathers user information - and/or clears its values.

Is this right? And is there a way to make the two cohabit peacefully?

Any help/guidance on this learning curve gratefully received.

David
GreyHead 29 Sep, 2010
Hi austega,

I'm not completely sure but the Profile Plug-in does overwrite the values.

The simple answer is to take all this code out of the Form HTML and move it to the OnSubmit Before box.
<?php
$user =& JFactory::getUser();
JRequest::setVar('username', $user->username);
JRequest::setVar('email', $user->email);
JRequest::setVar('name', $user->name);
JRequest::setVar('user_id', $user->id);
?>


Bob
austega 05 Oct, 2010
Thanks Bob.

Sorry for the late reply - my attempts to subscribe to my threads are not yet successful.

Your suggestion worked well.

For anyone finding this thread later, what I did was:
1. Add Bob's code as he suggested
2. Deleted the following from my quoted form html

<?php
if ( !$mainframe->isSite() ) { return; }
$user =& JFactory::getUser();
?>

<input type='hidden' name='username' value='<?php echo $user->username; ?>' />
<input type='hidden' name='email' value='<?php echo $user->email; ?>' />
<input type='hidden' name='name' value='<?php echo $user->name; ?>' />
<input type='hidden' name='user_id' value='<?php echo $user->id; ?>' />
alexidro 11 Mar, 2011
Hi, I have encountered the same problem. The solution works for email but what if I want also to save user data into a table?

I was in the same situation of austega, I first created a form with user data script, then created a table and everything OK. But then I added that script to 5-6 other forms and when I went to create the tables the "username" "name" and "email" were not on the list of possible entries.
And also it's impossible to create a table with that entries with the first original form from where I was able before.

In html code I also named every input with different names, id, and so on just for try, but nothing.

...sorry for my english...
GreyHead 11 Mar, 2011
Hi alexidro,

I'm sorry I don't completely understand the problem, an example might help.

In general you don't need to save user information in a table except for the User ID. If you have a cf_user_id column in the table then ChronoForms will automatically save this.

With the User ID you can easily look up any other User information.

Bob
alexidro 11 Mar, 2011
Thank you for fast reply!
Sorry, I'm a newbie.
But I understood, you are right, but I don't know how to do it, so filling in a hidden box within the form was a lot convenient.
Maybe it's not the right place to ask but can you explain me how can I show in the same frontend page the data from a form stored in a table and the username and other user info related to the user ids that submitted the form?
Many thanks
GreyHead 11 Mar, 2011
Hi alexidro,

That's a very general question and difficult to answer in a short post.

Please ask something much more specific, or give an example of something that you need to do.

Bob
alexidro 11 Mar, 2011
Thanks.

I have to do the following for example:
have a table called "jos_chronoforms_example", where the from "example" store the data.
I want registered users with special permissions to see a page with that informations submitted by users (the form is avaiable only to registerd users).
So i created a page with chronoconnectivity to show that (and is working ok), but I want also to show username, email and real name of the user that submitted that information, how to retrieve also that in relations to uid from the users table?

Many thanks
GreyHead 12 Mar, 2011
Hi alexidro,

In the ChronoConnectivity Header box, or a ChronoForm Form HTML box you can use
<?php
$user =& JFactory::getUser();
echo "Username: ".$user->username;
echo "Name: ".$user->name;
echo "E-mail: ".$user->email;
?>
You'll need to add suitable HTML for the layout you need.

Bob
alexidro 12 Mar, 2011
Maybe I didn't explain well or maybe I didn't understood welle the reply.
If I put the code you wrote in the chronoconnectivity header I show the data of the user is logged at the moment and is watching the table.
I don't wanna show that, but like the other data from the MySql table I wanna show the username that entered the data, not the one is watching that.
Hope to have explained well this time.
Thanks a lot!
GreyHead 12 Mar, 2011
Hi alexidro,

Assuming that the user id of the creator is in the cf_user_id column you can do this
<?php
$user =& JFactory::getUser($MyRow->cf_user_id);
echo "Username: ".$user->username;
echo "Name: ".$user->name;
echo "E-mail: ".$user->email;
?>

Bob
alexidro 12 Mar, 2011
Ok, I did it, in a way or another!
For other newbies like me I post how I did:

This code in the Onsubmit box before, as you told:
<?php
$user =& JFactory::getUser();
JRequest::setVar('username', $user->username);
JRequest::setVar('email', $user->email);
JRequest::setVar('name', $user->name);
JRequest::setVar('user_id', $user->id);
?>


Then table created with "Create Table" and added fields where I wrote "username", "name", "email" and enabled them and enabled DB connection to the table so now my table is filled with that informations that will last there forever, and in chronoconnectivity html I can simply call them with non issues.

Is this procedure right in your opinion, will it work forever with many differnt forms?

Thanks a lot, a beer is coming for you!
GreyHead 12 Mar, 2011
Hi alexidro,

That will work . . . and it's a pretty bad way to do it. If the user makes any changes in their name or email, etc, those changes will never show up in this listing.

As a general rule save data once only. The user data is saved in the jos_users table, keep it there and link to when you need it.

Did you try the last example I posted for you?

Bob
alexidro 12 Mar, 2011
Yes you're right, I also thinked that later but, for this kind of project I'm doing this is not influent because only I can register users (user registration disabled from frontend) and the username and name is the costumer company name (it's a B2B).

Anyway I want try your last example as well for future reference that's the way of course, but, sorry my inexperience, I didn't understood very well how to do it...where to put what, sorry can you explain step by step?
GreyHead 12 Mar, 2011
Hi alexidro,

How do you want the User information to be used? That will decide where the code goes.

Bob
alexidro 12 Mar, 2011
1.Only registered users can submit the form.
2.The form informations are stored in a table and sent by email.
3.Special Users (editors) can see and watch the informations stored by a chronoconnectivity frontend view.
4.In the same chronoforms view I want to simply show username, name and email of the user that submitted the data
GreyHead 12 Mar, 2011
Hi alexidro,

Then in the Body Box.

Bob
alexidro 12 Mar, 2011
Ok, it works!
Many many thanks!
This topic is locked and no more replies can be posted.