Documentation - Add user Frontend Documentation
Tuesday, 19 July 2011 00:21

In this DOC I will explain how you can add extra input fields to the add user frontend component. In this case the extra fields will go in the sql table of Community builder. So we dont need to write an additional mysql query. We just need to add the fields, validate the fields with javascript and insert the data of the fields in the database. This data goes to the table #__comprofiler.

To do this you will have to edit some HTML and PHP documents. You need to have an FTP connection and HTML editor (like dreamweaver)  to edit the codes so if you really dont know what that even means dont even try it. But it is not that difficult if you know just a little bit of HTML and PHP.

Tip!: Before you start, dont put any code in php IF or ELSE statements like:

<?php if( $namemode == "1" ): ?>

//here is some code

<?php else: ?>

 

Tutorial: Adding extra fields for Community Builder

1. Open this file on your server: components/com_adduserfrontend/views/adduserfrontend/tmpl/default.php

Now we are in the file we need to edit. The first thing to do is to create a new inputfield in the form.

 

2. Do  a search for return validate_form(this); in your code editor, and go to the line were that code is found.

Now you are in the form. As you probably know all input fields go in between the <form></form tags.

 

3. Add a new inputfield to the form.

<input type="text" name="FIELDNAME" value="" />

The form is build with a table so you probably will copy an existing row and edit it for your need:

<tr>

<td>FIELDTITLE: </td>

<td><input type="text" name="FIELDNAME" value="" /></td>

</tr>

The joomla 2.5 and 3 versions are slightly different from the Joomla 1.5 version. For Joomla 2.5 and 3 we will PHP echo the HTML:

echo '<tr><td>FIELDTITLE:</td><td><input type="text" name="NAME-OF-FIELD" value="''" /></td></tr>';

 

4. Do  a search for if (validate_required(password in your code editor.  (This step is optional. Only needed if you want to make required fields)

This will bring you to a piece of the javascript which validates the fields. You will have to add a new line of code to validate the field. Add this line under  the <?php endif; ?> that you can see there.

This is the code:

if (validate_required(FIELDNAME,"<?php JText::printf( 'ALERT_MSG_HERE') ?>")==false) {

FIELDNAME.focus();

return false;

}

The joomla 2.5 and 3 versions are slightly different from the Joomla 1.5 version. For Joomla 2.5 and 3 we will PHP echo the HTML:

echo 'if (validate_required(FIELDNAME,"'.JText::_("ALERT_MSG_HERE").'")==false) {

FIELDNAME.focus();return false;}';

}

ALERT_MSG_HERE is the message that will be showed  when the user fails to fill out the field. In this case it is a text from a language file. For websites with multiple languages. But you can also use it without language file. In that case just type your message where you see ALERT_MSG_HERE

 

5. Do  a search for $_POST['import'] in your code editor.

Now we are in the part of the script were we fetch the data which was submitted from the form. Here you must fetch the data from your inputfield:

$FIELDNAME = trim($_POST['FIELDNAME']);

We have loaded the post data in a php string for usage.

 

6. Do  a search for comprofiler in your code editor.

Now you are at the part of the script ware the data is inserted in the mysql database. We want to insert our php string here. You will see this code:

$sql ='INSERT INTO ' . $table_prefix . 'comprofiler SET

`id`              = "'. $user_id . '",

`user_id`         = "'. $user_id . '",

`firstname`       = "' . $firstname . '",

`lastname`              = "' . $lastname . '",

In the Joomla 2.5 and 3 version the code looks like this:

 

$sql3 = "INSERT INTO ".$db->nameQuote('#__comprofiler')." SET

".$db->nameQuote('id')."                  = ".$db->quote($user_id).",

".$db->nameQuote('user_id')."             = ".$db->quote($user_id).",

".$db->nameQuote('firstname')."           = ".$db->quote($firstname).",

".$db->nameQuote('lastname')."            = ".$db->quote($lastname).",

You will add a line of code under "lastname" like this:

`CB_FIELDNAME`              = "' . $FIELDNAME . '",

In the Joomla 2.5 and 3 version you will add a code like this:

".$db->nameQuote('CB_FIELDNAME ')."                = ".$db->quote( $FIELDNAME ).",

 

FIELDNAME:
As you probably might have guessed FIELDNAME is the name of you inputf field and php string. You will replace it with your own fieldname everywhere.

CB_FIELDNAME:
As you probably might have guessed CB_FIELDNAME is the name of the column in your database. So if you want it to work you should create a new field in the Field Management of Community Builder. The name of your field will always start with cb_ . So you must replace CB_FIELDNAME with you own cb_fieldname.

 

Now you can go test if it works. If you followed my steps to the letter all will work ;)

Last Updated on Thursday, 10 November 2016 14:09
 
Copyright © 2009 - 2019 Sitemap

This website uses cookies for analysis and ad placement. By continuing to use this website, you agree to our use of cookies on your computer