Forums

How to get the connected user and email ?

r4z 02 Nov, 2009
Hi, I've just installed Chronoforms, and it seems to be a very powerfull component !

I've created my first form, with textboxes and datepickers.

But I would like to add 2 hidden fields which contains automatically the connected user fullname and email in order to show it in the complete emailed form and to send a confirmation mail to the person who's filled the form.

Is it possible?

Thx for help and for this beautiful component !
GreyHead 02 Nov, 2009
Hi r4z,

Sure, you can get the user info from the Joomla User object:
<?php
$user = & JFactory::getUser();
?>
<input type='hidden' name='email' value='<?php echo $user->email; ?>' />
<input type='hidden' name='name' value='<?php echo $user->name; ?>' />

Bob
r4z 03 Nov, 2009
Thanks a lot for your answer.

Where can I put the code? In "Main onLoad/View Code" > "HTML code" ?
GreyHead 03 Nov, 2009
Hi r4z,

The code with the hidden fields must go in the Form HTML box.

Bob
r4z 03 Nov, 2009
Nice thx🙂 it works great !

I've only got one issue in the mailing : {name} and {email} are visible in the mail content, but it doesn't work in the "From Email", "ReplyTo Email" and "Subject", it's showing strings "{name}" and "{email}". How can I resolve that please?
GreyHead 03 Nov, 2009
Hi r4z,

The "From Email", "ReplyTo Email" and "Subject" fields are all static, they do not change with form results. So they must contain text strings - valid emails for the first two.

If you want to use dynamic values then use the Dynamic ReplyTo Email, etc. and put field names in the boxes (with no quotes or brackets).

If you use ReplyToEmail then you may well need to use ReplyTo Name with it.

Bob

PS I strongly recommend that you do not use Dynamic From Email, your emails may be marked as spam and lost if you do.
r4z 03 Nov, 2009
Ok, it works great.

For the dynamic subject, is it possible to mix static char string and a field content?

PS: I'm on an intranet, there is no problem for the spam
GreyHead 03 Nov, 2009
Hi r4z,

You can mix fields and text in the box there but you can pre-process in the OnSubmit Before Box
<?php
$field_name = JRequest::getString('field_name', '', 'post');
$subject = "The value of field 'field_name' is $field_name";
JRequest::setVar('subject', $subject);
?>
Then use subject in the Dynamic Subject field.

Bob
r4z 03 Nov, 2009
thx again and again ^^

2 other last thing lol (I hope).
First one : I'm forcing the user connection by putting this condition in the HTML form code (in order to prevent the from nobody mail or mail not sent) :

<?php
$user = & JFactory::getUser();
//var_dump($user);
if( $user->email != '' and $user->name != '' ){
....the form content
}else{
....No way you need to connect
}
?>


is it the better way to do it, or is there a special option to do it automatically?

Second one: I'm french and the datepicker format is american with sundays as First day of week, how can I manage that?

thx for your great help and fast answers !
GreyHead 09 Nov, 2009
Hi r4z,

You can use
<?php
$user =& JFactory::getUser();
if ( !$user->id ) {
  //the form content
}else{
 //No way you need to connect
}
?>

Bob

PS The Watchman plugin also handles this kind of check.
This topic is locked and no more replies can be posted.