Support This Site

Enhancing the contact form Print E-mail
Written by Peter Koch   
Tuesday, 19 October 2004

With two lines of embedded code you can enhance your contact form, so it prefills the name and email for registred users:

The record of the current visitor is stored in the global variable $my. Enter this code into the value field of the name:

<?php global $my; return $my->name; ?>

And this code into the value field of the email:

<?php global $my; return $my->email; ?>

For unregistred guest both entryfields will still be empty, but for logged in members the fields are now preset.

If you want to know more about $my, use phpMyAdmin and have a look into the table mos_users

Comments

boesh
2004-12-03 11:36:18
Is it possible to add those two lines of code into the original com_contact/contact.php?
Guest
2005-01-14 15:32:44
what file do i need to edit? under what folder? sorry, i'm new to this stuff :)
Guest
2005-02-17 15:06:00
excellent info on variables! Thanks Peter.
Guest
2005-03-31 08:32:43
Do you guys know if its possible to pull data from other tables in mambo - such as profile data from the comprofile tables used by the community builder module in the same manner outlined above?
Guest
2005-06-02 18:20:02
that's extremely helpful 
 
:) 
 
Paul
babubo
2005-08-24 05:32:09
i need this with the data from the mos_comprofiler 
Partic
2006-05-20 03:23:37
After researching it this evening and eventually not getting far, I sorted out the following code to reference fields from the mos_comprofiler table and pass the values to the facile forms fields. Place this in the value field. In this example, I have a cb_company field. The field name should be the only aspect you need to change. 
Partic
2005-09-30 11:27:50
Code didn't show in the post below: 
 
Partic
2005-09-30 11:28:15
< ? php global $database,$my; $query = "SELECT cb_company FROM #__comprofiler WHERE id = ". $my->id; 
$database->setQuery( $query ); $fieldvalue = $database->loadResult(); return $fieldvalue;?>
Partic
2005-10-01 01:39:05
Below is an example of a small segment of code that accesses the mos_comprofiler table to access the custom cb_company field. 
 
To access other fields in mos_comprofiler, just change the name of the field. 
 
To access fields in mos_users that aren't accessible by $my->id, use #__users for the table and which ever field name you need instead of cb_company. 
 
To access fields in other tables that have $my->id able to be used as a key, substitute the relevant table and field names.
jpdiamond
2006-03-17 12:33:09
When I use the above code in the VALUE of my form field, The field fills out properly with a value! However, I get a popup window with a DNS Error / Can't Find Server. This pops up in Facile Forms design time and live on the site. 
 
What am I doing wrong?
johnhansen
2006-05-26 10:05:40
The following code is not functioning as described above: 
 
< ? php global $database,$my; $query = "SELECT cb_company FROM #__comprofiler WHERE id = ". $my->id;  
$database->setQuery( $query ); $fieldvalue = $database->loadResult(); return $fieldvalue;?> 
 
Suggestions? 
 
Joomla 1.0.8 
 
Thanks 
 
JOHN
SirBerberitz
2006-06-01 10:23:52
< ? php global $database,$my; $query = "SELECT cb_company FROM #__comprofiler WHERE id = ". $my->id;  
$database->setQuery( $query ); $fieldvalue = $database->loadResult(); return $fieldvalue;?> 
 
OK, I'm trying to insert in a field called "Firma" the name of the company which was entered before and is now stored in the table "jos_user_extended" in the field "user1". 
 
< ? php global $database,$my; $query = "SELECT user1 FROM #__user_extended WHERE id = ". $my->id;  
$database->setQuery( $query ); $fieldvalue = $database->loadResult(); return $fieldvalue;?> 
 
I just get the following result in the "Firma" text area: 
 
< ? php global $database,$my; $query =  
 
 
I have no clue where to search the error so please help me !!! 
 
Thanks in advance! :?  
 
 
SirBerberitz
japasco
2006-10-03 13:20:10
This code works for me (removed the spaces at the begining and change cb_company with company) 
null[Joomla 1.0.11 and CB 1.0.1 stable] 
 
id;  
$database->setQuery( $query ); $fieldvalue = $database->loadResult(); return $fieldvalue;?> 
 
Best regards, 
 
Jorge
japasco
2006-10-03 13:22:50
This code works for me (removed the spaces at the begining and change cb_company with company) 
[Joomla 1.0.11 and CB 1.0.1 stable] 
 
id;  
$database->setQuery( $query ); $fieldvalue = $database->loadResult(); return $fieldvalue;?> 
 
Best regards, 
 
Jorge
japasco
2006-10-03 13:25:46
I mean write this without spaces: 
 
sts but wrap my text when write the complete code) 
 
Best regards, 
 
Jorge
verblakt
2006-11-26 15:37:00
Your downloadsection is down :sigh  
 
I get this error: 
Fatal error: Cannot instantiate non-existent class: dmconfig in /home/formfaci/public_html/administrator/components/com_docman/classes/DOCMAN_config.class.php on line 88
partic
2006-12-02 06:16:41
More so I don't have to remember it, but also to share it, here's the code to insert for Firstname and Lastname using Community Builder. 
 
To activate it in the textarea you drop it into, remove the space between setQuery($query); 
$database->query();$fieldvalue = $database->loadResult(); return $fieldvalue;?> 
 
id; $database->setQuery($query); 
$database->query();$fieldvalue = $database->loadResult(); return $fieldvalue;?>
cyrulution
2006-12-13 00:58:12
It works excellently. But I always get a debug window with things like  
----------------------------------------------------------- 
** AUSNAHMEBEDINGUNG DURCH FACILEFORMS AUFGEFANGEN *** 
PHP Fehlerstufe : E_NOTICE 
PHP Dateiname : /home/www/web42/web/components/com_facileforms/facileforms.process.php 
PHP Zeilennummer: 686 
Fehlermeldung : Use of undefined constant PREG_OFFSET_CAPTURE - assumed 'PREG_OFFSET_CAPTURE' 
---------------------------------------------------- 
How can I get rid of it? 
Cyrus
jflowers
2007-02-21 10:51:27
Alignment? 
 
Works fine but the text for name and email aligns with x=0 even though the FF value is x=5. 
 
Any idea how to fix this?
jflowers
2007-02-21 11:03:22
Never mind. It helps to align the name and email value fields with the nudger. Interesting how a text element is used to outline the border box while a following text/html element is used for the value.
valhario
2007-05-01 04:47:17
hello guys, i need to know how to create submit button that automatically send the form to my e-mail. 
thank you for your help.
toltec
2007-11-01 15:41:28
Cool, but... remove the space between the ; and the php closing tag if the space bothers you in the input area for guest visitors.
sigi
2008-09-11 15:36:49
Hi folks! 
 
I'm new to ff and have a question regarding this topic ... 
 
i've put this code: 
 
name;  
$database->setQuery($query); $fieldvalue = $database->loadResult(); return $fieldvalue;?>  
 
in the value box of a textaera. the database table adressen exists ( and yes, its in the same database but without the joomla prefix ...) , and the field adressen.num matches the $my->name field so it should return the field adressen.nachname ... but the field is empty. 
 
Another field i've put this code in : 
 
username; ?> 
 
and on entering the form that field is filled .. 
 
whats wrong with the first code? 
 
 
if i get this working i woud like to fill the textarea with some more database fields from that database, like name, adress, city, etc ...

Only registered users can write comments.
Please login or register.

 
Next >