• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Automatically fill the fields email and name

Automatically fill the fields email and name 2 years 10 months ago #41298

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
Hello
How can we make that the fields email and name are automatically filled for a connected user ?
If possible, I would also like to fill another field from a user custom field (Company).
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41302

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
The following user(s) said Thank You: contact827

Automatically fill the fields email and name 2 years 10 months ago #41303

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
Thanks. It works for the fields name and email.
But how can we also enter automatically a custom field of user ?
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41307

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
You might have to research that one, I've never done it with custom fields.
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 2 years 10 months ago by iceferret.
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41308

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
I tried the code :
//<code>
    $db = JFactory::getDbo();
    $db->setQuery("SELECT `column_name` FROM `#__table_name` WHERE `column_name`='value' LIMIT 1");
    return $db->loadResult();
    //</code>

In this code I replaced column-name and table-name by my datas : label and abc_fields_values
But I get always an error message : 1146 : Table 'myaccount_abc.#__#__ fields_values' doesn't exist.

I'm not a coder, so, in this code what exactly must be replaced by the column name, and the table name ?
Last Edit: 2 years 10 months ago by contact827.
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41326

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
That won't work anyway because there's no relationship between the custom field and the user in the database. so there's no way of saying 'select company from #_fields where username = 'username' so you would need to set up a foreign key in your database. probably not worth all the extra effort.
An alternative might be to auto-populate a dropdown field with all the companies you have entered already and let the user select?

autopopulate list
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41327

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
there's no relationship between the custom field and the user in the database

I think there is one. Each user has his own value of custom fields.
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41333

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
You're right, I created a user profile custom field. Tracked down where the entered value is held (#_user_profiles) and yes the table contains the user id so it's just constructing the appropriate query.
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41334

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
Ok so this works for me, you'll have to substitute your own database column names etc. Put the script in PHP scripts - pre-processing
//get the logged in user id
          $user = JFactory::getUser();
//assign to variable to use in query
          $user_id = $user->get('id');
 
//get the database object 
         $db = JFactory::getDbo();
         $db->setQuery("SELECT `value` FROM `rsf123_joom3`.`aaa2_fields_values` WHERE `item_id`= $user_id LIMIT 1");
//assign result of query to variable 
$value = $db->loadResult();
 
//change 'your website' to your own field name
$val['your website'] = $value;
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 2 years 10 months ago by iceferret.
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41335

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
It also works if you put the code in the field as the default value....just leave out the last line and add the //<code>......//</code> tags around it
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41342

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
I suppose that, with only 1 user custom field, this :
$db->setQuery("SELECT `value` FROM `rsf123_joom3`.`aaa2_fields_values` WHERE `item_id`= $user_id LIMIT 1");
Becomes this :
$db->setQuery("SELECT `value` FROM `rsf123_joom3` WHERE `item_id`= $user_id LIMIT 1");

I don't understand what to do with that :
/change 'your website' to your own field name
$val['your website'] = $value;
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41343

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
No, the query will not change, whether you have 1 or 1000 user custom fields, let's deconstruct it:
$db->setQuery("SELECT `value` FROM `rsf123_joom3`.`aaa2_fields_values` WHERE `item_id`= $user_id LIMIT 1");
in the above `value` is the name of the column we want to select the data from.
`rsf123_joom3`.`aaa2_fields_values` is the table name where the column `value` is found. In this case, it is composed of two parts, to the left of the . is the database name, to the right is the table name.

finally, we use the WHERE on the `item_id column which is in the same table and contains the unique user id's for registered users so we can ask for only results where the ìtem_id` is the same as the user_id we got with
$user_id = $user->get('id');
You might need to check your database (PHPadmin or workbench) to confirm the correct name.table_name

I probably wasn't clear enough on the last part. I created a custom user field 'your website' to check the query worked. if your custom field is 'company' or whatever you named it then it would be
$val['company'] = $value;
What we are doing here is returning the result of the query (which is now in the $value variable) back to the form field.
Does that help clarify things a bit?
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 10 months ago #41344

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
I tried this with my database and tables names, but I'm sure I made mistakes, because I get in frontend :
1054 - Unknown column 'value' in 'field list'
or
1146 - Table 'abc_mytable29.#__fields_value' doesn't exist
(I changed the real name of the database).

For example, for a custom field "Company" I don't know if I must use the table :
- abc_fields_value (with all the companies names of the users in the column "value"), or
- abc_fields , with just "Entreprise" (in french) in the column "value".
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 9 months ago #41357

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
You would use;

- abc_fields_value (with all the companies names of the users in the column "value")

Just a thought you are using back ticks in the query not standard commas?
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Automatically fill the fields email and name 2 years 9 months ago #41419

  • contact827
  • contact827's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 56
  • Thank you received: 3
Hi. I didn't know that "backticks" should be used somewhere, but anyway I just copied/paste the code you gave.
I will try again soon.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!