I've managed to get a Chronoform working and have its contents added to the CB tables. However, my CB registration form uses firstname and lastname, instead of just 'name'. When using the CB registration form, the two fields together will form what is added to Joomla Users table as 'name'.
Now, this doesn't work when I use Chronoforms. The CB plugin configuration has a field 'Name', but I cannot fill out 'firstname' and 'lastname' together there.
And if I choose only 'firstname', obviously the Joomla user table gets updated with only the first name as 'name'.
Is there anything I can do to change that, so that people can still fill out their first and last name in separate fields, but they get combined in the Joomla users table's 'name' field?
Put a 'dummy' hidden field in your Form HTML
<input type="hidden" name="name" value="" />
Then in the OnSubmit Before box for your form set a value for this field<?php
$first_name = JRequest::getVar('first_name', '', 'post');
$last_name = JRequest::getVar('last_name', '', 'post');
$name = $first_name." ".$last_name;
JRequest::setVar('name', $name, 'post');
?>
Use the 'name' field name for the Joomla Registration PlugIn entry.Bob
PS Not tested and may need de-bugging (could also be simplified but the full code is clearer).
Later: corrected to add missing quotes and changed 'full_name' to 'name'
Exactly as Bob said, but because the Joomla users table name field is called "name" then we will change the last line of Bob's code to be:
JRequest::setVar('name', $full_name);
Cheers
Max
Regards
Max
This is what I get upon hitting the submit button:
Parse error: parse error, unexpected T_STRING in ..............com_chronocontact/chronocontact.php(401):eval()'d code on line 3
I've looked at the chronocontact.php file, and I'm guessing it's line 401 in chronocontact.php, where it says:
eval( "?>".$rows[0]->onsubmitcodeb4 );
and that line 3 refers to the 3rd line of the code I entered in the "On Submit code - before sending email:" box.
My formfields (both in CB and Chronoforms, are called firstname and lastname, so I adjusted your code to:
<?php
$first_name = JRequest::getVar('firstname', '', 'post);
$last_name = JRequest::getVar('lastname', '', 'post);
$full_name = $first_name." ".$last_name;
JRequest::setVar('full_name', $full_name, 'post');
?>
I really don't see where the unexpected T_STRING would be, but maybe the cause would be elsewhere?
Don't I have to add some code somewhere to make "JRequest" work? I don't know if this would be different between the different Joomla versions, I'm using 1.0.15.
It's line 3 (and 2) of the code I posted - there's a quote missing after the final 'post . . . it should of course be 'post'
I'll go back and correct my original posting.
Sorry about this, we rattle off code from memory, nine time out of ten it's OK and the tenth time it's fatally flawed - but of course you can't see the mistakes in your own code :-(
For Joomla 1.0.x you can't use JRequest, the corresponding code is
<?php
$_POST['name'] = $_POST['first_name']." ".$_POST['last_name'];
?>
Bob
It's line 3 (and 2) of the code I posted - there's a quote missing after the final 'post . . . it should of course be 'post'
I can't believe I missed that. Really, I even looked for missing quotes, and I simply didn't see them 😶
but of course you can't see the mistakes in your own code :-(
Means I should have seen it, right? ;-)
For Joomla 1.0.x you can't use JRequest, the corresponding code is
<?php
$_POST['name'] = $_POST['first_name']." ".$_POST['last_name'];
?>
Thanks, that works like a charm :-)
I have one more question, but since it's an almost entirely different subject, I'll start a new topic for that one.
Thanks again!
JRequest::setVar('name', JRequest::getVar("first_name")." ".JRequest::getVar("last_name"));
Regards,
Max
Anyway, mine didn't work? I've probably made a mistake somewhere, but not sure where?
Here are steps and code I did:
1. Put the following code into the form - I did it in my Chronoform in the tab "Form Code" in the Form HTML.
I put this line right at the start: <input type="hidden" name="name" value="" />
2. I Put the following code into the same tab but in the On Submit code - before sending email:
<?php
$first_name = JRequest::getVar('first_name', '', 'post');
$last_name = JRequest::getVar('last_name', '', 'post');
$name = $first_name." ".$last_name;
JRequest::setVar('name', $full_name);
?>
3. Plugins tab - only CB Registration is ticked.
It still asks for a name (Please enter your name:) on landing page after submitting the information - I get an email with form fields, with an attached image (have file upload working) but nothing back end user. 😢
I was thinking - maybe because Name Field is empty in CB Registration plugin it needs SOMETHING in there??
Do I have to fill in anything in Joomla Registration plugin?
Thanks, in advance.
I haven't had my morning coffee yet so may get this wrong. I think that there's a typo in your code in line 3 you create a $name variable but in line 4 you use $full_name - make them both the same.
AFAIK you only need the CB Registration working.
Bob
I have tried everything in this string. I am using Joomla 1.5.8 and CB 1.2
I get the following error.
Fatal error: Call to undefined method stdClass::getError() in /home/msrctest/public_html/components/com_chronocontact/plugins/cf_cb_registration.php on line 245
Here is the code i put in the on submit:
<?php
$first_name = JRequest::getVar('first_name', '', 'post');
$last_name = JRequest::getVar('last_name', '', 'post');
$name = $first_name." ".$last_name;
JRequest::setVar('name', $full_name, 'post');
?>
I also can't use the 'name' field in either my CB plugin or Joomla plugin
It's kind of strange it saves my registration but it won't save my last name.
Bilal
Looking at another thread this morning it seems that there is a problem using the ChronoForms Plugin with the CB 1.2 RC releases. CB 1.1 stable should be OK though.
Bob
I needed a way to combine the firstname and lastname fields for Joomla registration, while still having first_name and last_name fields to pass to the authorize.net plugin.
Thanks Bob!
Hi Els,
Put a 'dummy' hidden field in your Form HTML
<input type="hidden" name="name" value="" />
Then in the OnSubmit Before box for your form set a value for this field<?php
$first_name = JRequest::getVar('first_name', '', 'post');
$last_name = JRequest::getVar('last_name', '', 'post');
$name = $first_name." ".$last_name;
JRequest::setVar('name', $name, 'post');
?>
Use the 'name' field name for the Joomla Registration PlugIn entry.Bob
PS Not tested and may need de-bugging (could also be simplified but the full code is clearer).
Later: corrected to add missing quotes and changed 'full_name' to 'name'
Thanks - glad it worked for you.
Bob
PS YOu can also use this in the Before Code box in the Plugin (it it's working - not all of them are).
I'm not able to get the message sent because it appears that the $_POST['rep_email'] isn't being set. I've put my code in the before send email code box.
Code in form:
<input type="hidden" name="rep_email" value="" />
Code in On Submit code - before sending email:
$_POST['rep_email'] = [email]'email@address.com[/email]'; //I have verified that I am passing a valid email address.
CC field name code:
rep_email
Can anyone help me?
If the value of a hidden field is value='' then there won't be any value in the $_POST array.
You need to add the value there - or, better, look up the address in the OnSubmit box and add it to the $_POST array.
Bob
Where is the value supposed to come from?? There's no code here that sets it.
Bob
Code in On Submit code - before sending email:
It is able to get a valid email address, but I need to include it with the email notification for the form being submitted.
Anyone?
Hmmm I don't remember any of the code for Joomla 1.0 now - maybe if you dig far enough back in the forums. And are you using the CB registration plugin here?? I've got a bit confused about what is happening.
Bob
I strongly recommend that you upgrade. Joomla 1.0 is no longer supported at all. And I understand that may not be possible.
I'm sure that the answer you need is in the forums here but you will need to be searching a year or more into the history. I'm afraid that I can no longer remember how to do that.
I'd suggest that you try a Google search on the forums as it seems to get better results than the forum search.
Bob
Hi Els,
Exactly as Bob said, but because the Joomla users table name field is called "name" then we will change the last line of Bob's code to be:
JRequest::setVar('name', $full_name);
Cheers
Max
Hi Max,
With regard to combining "First Name" and "Last Name" into single "Name" field for Joomla Registration:
I know this is an old post but I think it is exactly what I'm looking for. Unfortunately I can't get it to work for me (I suspect I'm doing something wrong as I am still learning 🙄 but I haven't been able to figure it out).
I'm using the Joomla Registration Plugin so I tried using your edit to Bob's code for the CB plugin. I have tried inserting the code in the "form code >> on submit code - before sending email" and (separately) the "Joomla Registration Plugin >> Extra code >> extra before reg. code".
The code I used is as follows:
<?php
$first_name = JRequest::getVar('text_9', '', 'post');
$last_name = JRequest::getVar('text_8', '', 'post');
$name = $text_9." ".$text_8;
JRequest::setVar('name', $full_name);
?>
^^ where 'text_9' & 'text_8' are the first name and last name fields respectively.
the code I inserted into the form html for the hidden field is as follows:
<input value="" id="hidden_30" name="name" type="hidden" />
...I tried the above with and without:
id="hidden_30"
When I click submit I am returned to a blank form and it says "Please enter your name".
Any ideas of where I'm going wrong?
Thanks in advance!
-Staecows
Put the PHP code into the Joomla Registration Before Code box.
The on the tab in the Plugin Configuration where you enter the input names just put name in the 'name' box.
You don't need the hidden field with this plugin.
Bob
I tried what you said (seems nice and logical!) but for some reason I'm still getting the same results. i.e. I get returned to a blank form with a red box on top telling me to "please enter a name".
I've gone over and over it again and although I can't see what I'm doing wrong and know I must have made a mistake somewhere. My exact setup/procedure at the moment is as follows - nothing more, nothing less:
1. I create a standard registration-type form (first name, last name, username, password, address, etc and no hidden fields). I experience no problems when it is not linked with the Joomla Registration Plugin. (if it matters: "email the results"=YES, "Debug"=ON).
2. Then, in Forms Management I click on the form and go to the Plugins tab and I enable "Joomla Registration" and it is at this point I encounter problems when trying to combine the First and Last name.
3. I insert the following code into the Joomla Registration Plugin before section in an attempt to combine the two separate name fields into one:
<?php
$first_name = JRequest::getVar('text_9', '', 'post');
$last_name = JRequest::getVar('text_8', '', 'post');
$name = $text_9." ".$text_8;
JRequest::setVar('name', $name, 'post');
?>
[text_9 is first name and text_8 is last name in my form]4. In the Joomla Registration Plugin set-up I enter relevant field names (e.g. text_12 for "email address" and name for "name"...).
I don't want to be asking to be spoon-fed with this issue because I'd rather figure it out myself but I'm afraid I've been defeated by this problem! :wink:
Here's hoping there's some small/obvious problem with my method that jumps out at you!
Thanks again,
Staecows
Here's hoping there's some small/obvious problem with my method that jumps out at you!
Ouch, it just jumped out in my left eye :-)
The problem is with the variables you feed into $name on line 4. Use this instead :
<?php
$first_name = JRequest::getVar('text_9', '', 'post');
$last_name = JRequest::getVar('text_8', '', 'post');
$name = $first_name." ".$last_name;
JRequest::setVar('name', $name, 'post');
?>
It just tried it (thanks to all the posters, it really helps), and it worked directly like that.
Cheers,
Paul-Henri
I'm a long time reader, but this time I cannot overcome this one:
I have a joomla1.7 site, and i'm trying to concatenate firstname/lastname.
I'm using version 4.0rc2.0 of chronoforms and i followed exactly the instructions above, but i keep receiving the message "you must provide your username" which should be set by first_name. last_name.
I'm thinking the problem might be somewhere in where i place the custom code to concatenate (see screenshot attached).[attachment=0]Untitled-2.jpg[/attachment]
Can anyone help?
Thanks in advance,
T.
In ChronoForms v4 the code is slightly different, this is a modified version that also handles the cases where one of the names is empty.
<?php
$name = array();
$name[] = JRequest::getVar('text_9', '', 'post');
$name[] = JRequest::getVar('text_8', '', 'post');
$form->data['name'] = implode(' ', $name);
?>
Bob