Drupal
Drupal Performance - Disable CSS Aggregation from database
Sometimes on our localbox [wamp : localhost] we found that when enabled css aggregation and javascript aggregation then we cannot able to access our admin area and user login area. I mean we cannot able to access the site because we enabled css aggregation. Now you cannot access the admin area and you cannot even login so what to do.
You have to disable your css aggregation from database using your phpmyadmin. Follow the below steps:
- Open phpmyadmin and select the database which is used by the drupal instance.
- Select the "variables" table.
- Search for "preprocess_css" in name field.
- Change the variable value to s:1:"0";
- And you are done.
So this is the way you can disable your css aggregation with the use of phpmyadmin. If you want to disable javascript aggregation, you have to follow the same steps and you have to search for "preprocess_js" in "variables" table in step 3. That's it!
If you have any tips like this let share here in comments.
PHP CMS Frameworks
August 27, 2014
Read more →
Wordpress
Create a simple wordpress ajax contact form without plugin
In this article, we are going to discuss about How to create a simple wordpress ajax contact form without plugin. WordPress is an Open Source project, which means there are hundreds of people all over the world working on it. (More than most commercial platforms.) It also means you are free to use it for anything from your cat's home page to a Fortune 500 web site without paying anyone a license fee and a number of other important freedoms.
Below is the code to create a simple ajax contact form without plugin in wordpress.
Step 1 :
Add the below code to your functions.php file
<?php
function addme_ajaxurl() {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
<?php
}
add_action('wp_head','addme_ajaxurl');
add_action('wp_ajax_submit_form', 'submit_form_callback');
function submit_form_callback(){
$params = array();
parse_str($_POST['data'], $params);
$name = trim($params['name']);
$email = $params['email'];
$message = $params['message'];
$subject = $params['subject'];
$site_owners_email = 'email@sitename.com'; // Replace this with your own email address
if ($name=="") {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&.-_+]+@[a-z0-9-]+.([a-z0-9-]+.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if ($message== "") {
$error['message'] = "Please leave a comment.";
}
if ($subject=="") {
$error['subject'] = "Please leave a subject.";
}
if (!$error) {
$mail = mail($site_owners_email, $subject, $message,
"From: ".$name." <".$email.">rn"
."Reply-To: ".$email."rn"
."X-Mailer: PHP/" . phpversion());
$success['success'] = "<div class='success'>" . $name . ", We've received your email. We'll be in touch with you as soon as possible! </div>";
echo json_encode($success);
} # end if no error
else {
echo json_encode($error);
} # end if there was an error sending
die(); // this is required to return a proper result
}
?>
Step 2 :
Add the below code in your html and JavaScript where you want show your form
<form method="post" action="#" name="contact-form" id="contact-form">
<div id="main">
<div id="response"></div>
<div class="fullwidth">
<label>Name:</label>
<p>
<input type="text" name="name" id="name" size="30" />
</p>
</div>
<div class="fullwidth">
<label>Email:</label>
<p>
<input type="text" name="email" id="email" size="30" />
</p>
</div>
<div class="fullwidth">
<label>Subject:</label>
<p>
<input type="text" name="subject" id="subject" size="30" />
</p>
</div>
<div class="fullwidth">
<label>Message:</label>
<p>
<textarea name="message" id="message" cols="30" rows="10"></textarea>
</p>
<p>
<input class="contact_button button" type="submit" name="submit" id="submit" value="Email Us!" />
</p>
</div>
<div class="fullwidth"></div>
</div>
</form>
<script type="text/javascript">
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
$('#response').empty();
var data = {
action: 'submit_form',
data: $( this ).serialize()
};
$.post(ajaxurl, data, function(response) {
console.log(response);
if(response.success){
$('#response').append(response.success);
}
if(response.name){
$('#response').append(response.name + "<br>");
}
if(response.email){
$('#response').append(response.email + "<br>");
}
if(response.message){
$('#response').append(response.message + "<br>");
}
if(response.subject){
$('#response').append(response.subject + "<br>");
}
},'json');
});
</script>
Below is the code to create a simple ajax contact form without plugin in wordpress.
Step 1 :
Add the below code to your functions.php file
<?php
function addme_ajaxurl() {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
<?php
}
add_action('wp_head','addme_ajaxurl');
add_action('wp_ajax_submit_form', 'submit_form_callback');
function submit_form_callback(){
$params = array();
parse_str($_POST['data'], $params);
$name = trim($params['name']);
$email = $params['email'];
$message = $params['message'];
$subject = $params['subject'];
$site_owners_email = 'email@sitename.com'; // Replace this with your own email address
if ($name=="") {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&.-_+]+@[a-z0-9-]+.([a-z0-9-]+.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if ($message== "") {
$error['message'] = "Please leave a comment.";
}
if ($subject=="") {
$error['subject'] = "Please leave a subject.";
}
if (!$error) {
$mail = mail($site_owners_email, $subject, $message,
"From: ".$name." <".$email.">rn"
."Reply-To: ".$email."rn"
."X-Mailer: PHP/" . phpversion());
$success['success'] = "<div class='success'>" . $name . ", We've received your email. We'll be in touch with you as soon as possible! </div>";
echo json_encode($success);
} # end if no error
else {
echo json_encode($error);
} # end if there was an error sending
die(); // this is required to return a proper result
}
?>
Step 2 :
Add the below code in your html and JavaScript where you want show your form
<form method="post" action="#" name="contact-form" id="contact-form">
<div id="main">
<div id="response"></div>
<div class="fullwidth">
<label>Name:</label>
<p>
<input type="text" name="name" id="name" size="30" />
</p>
</div>
<div class="fullwidth">
<label>Email:</label>
<p>
<input type="text" name="email" id="email" size="30" />
</p>
</div>
<div class="fullwidth">
<label>Subject:</label>
<p>
<input type="text" name="subject" id="subject" size="30" />
</p>
</div>
<div class="fullwidth">
<label>Message:</label>
<p>
<textarea name="message" id="message" cols="30" rows="10"></textarea>
</p>
<p>
<input class="contact_button button" type="submit" name="submit" id="submit" value="Email Us!" />
</p>
</div>
<div class="fullwidth"></div>
</div>
</form>
<script type="text/javascript">
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
$('#response').empty();
var data = {
action: 'submit_form',
data: $( this ).serialize()
};
$.post(ajaxurl, data, function(response) {
console.log(response);
if(response.success){
$('#response').append(response.success);
}
if(response.name){
$('#response').append(response.name + "<br>");
}
if(response.email){
$('#response').append(response.email + "<br>");
}
if(response.message){
$('#response').append(response.message + "<br>");
}
if(response.subject){
$('#response').append(response.subject + "<br>");
}
},'json');
});
</script>
PHP CMS Frameworks
August 24, 2014
Read more →
Joomla
Images Hotlink Protection using htaccess in Joomla
In this article, we are going to discss about How to protect the image Hotlink using htaccess in Joomla. Currently there are 2 ways to protect your images from being used illegally by other website and to prevent bandwidth loss. One general way is to activate and use built in Hotlink Protection in your cPanel and the other way is by directly editing your .htaccess file.
Setting up .htaccess specific to Joomla is a little bit different from ordinary website. It depends on your server type and also your access to this file.
But for some reason, not all .htaccess setting work on any server such as those who hosted their website on litespeed server. For the purpose of adding the function of hotlink protection, you may need to add in these lines on the very top of your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.yourdomain.com/x.gif [R,NC,L]
Why at the top?
To be true, I'm not in the position of really understanding the terms and explaining it to you. However, in Joomla 2.5 (as I know), you will need to put it on top of the list or else it won't work (It took me 2 days to figured it out...only after my web host provider informed me).
One thing that to note here - when you are using cPanel to manage your hotlink protection, it will automatically update your .htaccess file BUT the updated lines are usually added at the bottom of the .htaccess file. If that happened, you just need to relocate the lines.
For some reason, for those hosting on speedlite server, you'll need to extra lines:
RewriteEngine on
RewriteOptions Inherit
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?exadomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.exadomain.com/x.gif [R,NC,L]
As I said before, just contact your hosting provider should you encountered problem pertaining your .htaccess file (only after you failed to follow general guide). After all, your payment for hosting inclusive of after sale services.
Setting up .htaccess specific to Joomla is a little bit different from ordinary website. It depends on your server type and also your access to this file.
But for some reason, not all .htaccess setting work on any server such as those who hosted their website on litespeed server. For the purpose of adding the function of hotlink protection, you may need to add in these lines on the very top of your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.yourdomain.com/x.gif [R,NC,L]
Why at the top?
To be true, I'm not in the position of really understanding the terms and explaining it to you. However, in Joomla 2.5 (as I know), you will need to put it on top of the list or else it won't work (It took me 2 days to figured it out...only after my web host provider informed me).
One thing that to note here - when you are using cPanel to manage your hotlink protection, it will automatically update your .htaccess file BUT the updated lines are usually added at the bottom of the .htaccess file. If that happened, you just need to relocate the lines.
For some reason, for those hosting on speedlite server, you'll need to extra lines:
RewriteEngine on
RewriteOptions Inherit
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?exadomain\.com/.*$ [NC]
RewriteRule \.(gif|jpg|png)$ http://www.exadomain.com/x.gif [R,NC,L]
As I said before, just contact your hosting provider should you encountered problem pertaining your .htaccess file (only after you failed to follow general guide). After all, your payment for hosting inclusive of after sale services.
PHP CMS Frameworks
August 20, 2014
Read more →
Zend
Zend Framework - Content Indexing using Zend_Search_Lucene component
In this article, we are going to discuss about in Zend Framework How to index the content using Zend_Search_Lucene component. Lucene is indexing and retrieval library that originally was developed in Java technology and supported by the Apache Software Foundation. When the data has been indexed in the file system, it does not require a database server. Zend_Search_Lucene is one of the components of the Zend Framework that implements this technology.
Zend_Search_Lucene supports the following features:
Ok, let's go to the example:
Suppose we have data that we store the article in our index file system. We have a call controller Zend_Search_Lucene components as follows:
class TestluceneController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
$this->indexPath = APPLICATION_PATH.'/indexsearch/index';
}
}
In the init function, we declare the path where we store the index. If so, we created an action to index data from the database, such as the following:
//...................
public function reindexAction()
{
// action body
//just SAMPLE , access to db
// ( in your REAL DEVELOPMENT, access to db is only in model ) !!!!
//asumption , 'db' is already registered in registry !!!
$db = Zend_Registry::get('db');
$fetch = $db->query("select * from articles")->fetchAll();
$index = Zend_Search_Lucene::create($this->indexPath);
foreach($fetch as $key=>$row)
{
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('title', $row['title']));
$doc->addField(Zend_Search_Lucene_Field::UnStored('content', $row['content'] ));
$index->addDocument($doc);
echo 'Added ' . $row['title'] . ' to index.
';
}
//optimize index...
$index->optimize();
die;
}
//................................
Well, we run the action reindexAction first before attempting to scan the data. If so, now we can test:
//.......Search data is already indexed.
public function searchAction()
{
$data = array();
// If a search_query parameter has been posted, search the index.
$indexopen = Zend_Search_Lucene::open($this->indexPath);
// Get results.
$data = $indexopen->find('"PHP framework" AND "Zend Framework"');
foreach($data as $key=>$row)
{
echo $row->title; echo "<br>";
}
die;
}
//......................
Zend_Search_Lucene supports the following features:
- Ranking of search results
- Powerful query types: Boolean, wildcard, phrase queries
- Search by specific field
Ok, let's go to the example:
Suppose we have data that we store the article in our index file system. We have a call controller Zend_Search_Lucene components as follows:
class TestluceneController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
$this->indexPath = APPLICATION_PATH.'/indexsearch/index';
}
}
In the init function, we declare the path where we store the index. If so, we created an action to index data from the database, such as the following:
//...................
public function reindexAction()
{
// action body
//just SAMPLE , access to db
// ( in your REAL DEVELOPMENT, access to db is only in model ) !!!!
//asumption , 'db' is already registered in registry !!!
$db = Zend_Registry::get('db');
$fetch = $db->query("select * from articles")->fetchAll();
$index = Zend_Search_Lucene::create($this->indexPath);
foreach($fetch as $key=>$row)
{
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('title', $row['title']));
$doc->addField(Zend_Search_Lucene_Field::UnStored('content', $row['content'] ));
$index->addDocument($doc);
echo 'Added ' . $row['title'] . ' to index.
';
}
//optimize index...
$index->optimize();
die;
}
//................................
Well, we run the action reindexAction first before attempting to scan the data. If so, now we can test:
//.......Search data is already indexed.
public function searchAction()
{
$data = array();
// If a search_query parameter has been posted, search the index.
$indexopen = Zend_Search_Lucene::open($this->indexPath);
// Get results.
$data = $indexopen->find('"PHP framework" AND "Zend Framework"');
foreach($data as $key=>$row)
{
echo $row->title; echo "<br>";
}
die;
}
//......................
PHP CMS Frameworks
August 17, 2014
Read more →
Magento
Steps to add Icon to New Products in Magento
In this article, we are going to discuss about steps to add Icon to new products in Magento. As your inventory rises it's always very necessary to make your products stand out using an unique icon. Visitors to your website will be able to notice which products are newly arrived as the icon will show up in wherever you set it to in your theme.
Step 1 : Manage attributes
Go to Catalogue -> Attributes -> Manage Attributes. Set up a new attribute at this page and call it 'Boolean'. Set its ID as new_product. Under your advanced options, you will have the option to select it as a front end product. Do this. Now you simply have to add the new attribute to your custom attribute if you are using one. If not, set it to default. Save the new product.
You will now have a new product in your catalogue which has a Boolean flag set to yes. The next stage involves taking this new product icon and putting it in your front end.
Step 2 : Make it show
Now that you have a product icon with a Boolean flag, it's time to make this show on your front end. This is achieved by accessing template files: templates/catalog/product/list.phtml andtemplates/catalog/product/view/media.phtml.
<div class="product-image">
<?php if($_product->getNewProduct()) { ?>
<div class="new-product"></div>
<?php }
$_img = '<img id="image" src="'.$this->helper('catalog/image')
->init($_product, 'image').'"
alt="'.$this->htmlEscape($this->getImageLabel()).'"
title="'.$this->htmlEscape($this->getImageLabel()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
?>
</div>
As you can see, above, your new product is shows in '$_product->getNewProduct'. The next step is to ensure that your CSS is set up to show your product with Boolean flag. You need to make the product_class relative to the position of the icon. So:
.products-grid .product-image { position: relative; display:block; width:244px; height:156px; margin:0 0 10px; }
.new-product {
position: absolute;
right: 0;
top: 0;
width: 65px;
height: 66px;
display: block;
z-index: 2;
background: url(../images/new-product.png) no-repeat;
}
Step 3 : Save
Save your changes and ensure that your code is correct before doing so. Now, every time you add a new product and it goes on sale through your front end, it'll have an icon and Boolean flag.
Step 1 : Manage attributes
Go to Catalogue -> Attributes -> Manage Attributes. Set up a new attribute at this page and call it 'Boolean'. Set its ID as new_product. Under your advanced options, you will have the option to select it as a front end product. Do this. Now you simply have to add the new attribute to your custom attribute if you are using one. If not, set it to default. Save the new product.
You will now have a new product in your catalogue which has a Boolean flag set to yes. The next stage involves taking this new product icon and putting it in your front end.
Step 2 : Make it show
Now that you have a product icon with a Boolean flag, it's time to make this show on your front end. This is achieved by accessing template files: templates/catalog/product/list.phtml andtemplates/catalog/product/view/media.phtml.
<div class="product-image">
<?php if($_product->getNewProduct()) { ?>
<div class="new-product"></div>
<?php }
$_img = '<img id="image" src="'.$this->helper('catalog/image')
->init($_product, 'image').'"
alt="'.$this->htmlEscape($this->getImageLabel()).'"
title="'.$this->htmlEscape($this->getImageLabel()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
?>
</div>
As you can see, above, your new product is shows in '$_product->getNewProduct'. The next step is to ensure that your CSS is set up to show your product with Boolean flag. You need to make the product_class relative to the position of the icon. So:
.products-grid .product-image { position: relative; display:block; width:244px; height:156px; margin:0 0 10px; }
.new-product {
position: absolute;
right: 0;
top: 0;
width: 65px;
height: 66px;
display: block;
z-index: 2;
background: url(../images/new-product.png) no-repeat;
}
Step 3 : Save
Save your changes and ensure that your code is correct before doing so. Now, every time you add a new product and it goes on sale through your front end, it'll have an icon and Boolean flag.
PHP CMS Frameworks
August 13, 2014
Read more →
CakePHP
Using the Database for Sessions in CakePHP 1.3.3
In this article, we are going to discuss about How to use database for session in CakePHP version 1.3.3. In CakePHP 1.3.3, I had difficulty in finding the schema for the sessions table without using the command line to generate the table.
Below is the raw SQL, that can be used to create the table. I'm sure it will be useful in future for me so I thought I'd share.
CREATE TABLE `cake_sessions` (
`id` varchar(255) NOT NULL DEFAULT '',
`data` text,
`expires` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
Now you just need to modify the core.php file so that the database is used for Sessions instead of the default:
Configure::write('Session.save', 'database');
Update
To create the Sessions table from the console simply navigate to the /cake/console directory in the command line and run:
php cake.php schema create Sessions
Below is the raw SQL, that can be used to create the table. I'm sure it will be useful in future for me so I thought I'd share.
CREATE TABLE `cake_sessions` (
`id` varchar(255) NOT NULL DEFAULT '',
`data` text,
`expires` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
Now you just need to modify the core.php file so that the database is used for Sessions instead of the default:
Configure::write('Session.save', 'database');
Update
To create the Sessions table from the console simply navigate to the /cake/console directory in the command line and run:
php cake.php schema create Sessions
PHP CMS Frameworks
August 10, 2014
Read more →
YII
Steps to install new theme in YII PHP Framework
In this article, we are going to discuss about the step by step procedure to install the new theme in YII PHP Framework. In web application, designing also has same importance as development because user interface matters. If UI is not user friendly then ultimately application won't be useful. Here i'll show you brand new theme installation on yii php framework.
First we need some template compatible with yii framework. I found two template link which is free Theme1 Theme2 download both templates from given links. After downloading complete follow the steps.
Step 1:
Open your YII app folder where you've installed yii framework app.
Step 2:
Copy the template folder and paste it into the theme directory which exist in your app folder (/yiiapp/themes/)
Step 3:
Open the protected folder and find config directory and open it, in config directory there is one main.php file open it in any text editor.(/yiiapp/protected/config/main.php)
Step 4:
Make the following changes in the main.php ('theme'=>'themename',) here is the screen shoot of main.php file
Step 5:
It simply route your theme folder and find cleangrad if found load it
Step 6:
Check theme has been installed successfully. (http://localhost/yiiapp/)
First we need some template compatible with yii framework. I found two template link which is free Theme1 Theme2 download both templates from given links. After downloading complete follow the steps.
Step 1:
Open your YII app folder where you've installed yii framework app.
Step 2:
Copy the template folder and paste it into the theme directory which exist in your app folder (/yiiapp/themes/)
Step 3:
Open the protected folder and find config directory and open it, in config directory there is one main.php file open it in any text editor.(/yiiapp/protected/config/main.php)
Step 4:
Make the following changes in the main.php ('theme'=>'themename',) here is the screen shoot of main.php file
Step 5:
It simply route your theme folder and find cleangrad if found load it
Step 6:
Check theme has been installed successfully. (http://localhost/yiiapp/)
PHP CMS Frameworks
August 04, 2014
Read more →
YII
Steps to install YII php framework on ubuntu linux
In this article, we are going to discuss about How to install YII PHP Framework on Ubuntu Linux systems. YII is widely used best PHP Framework. Yii helps Web developers build complex applications. Yii is pronounced as Yee or [ji:], and is an acroynym for "Yes It Is!". Yii is a free, open-source Web application development framework written in PHP5 that promotes clean, DRY design and encourages rapid development. It works to streamline your application development and helps to ensure an extremely efficient, extensible, and maintainable end product.
Steps to install YII PHP framework on ubuntu linux
Step 1:
Download the latest version of YII framework from http://www.yiiframework.com
Step 2:
Extract downloaded YII framework tar.gz file in same directory
cd Downloads/
tar -zxvf yii-1.1.14.f0fee9.tar.gz
Step 3:
Rename extracted folder as yii
mv yii-1.1.14.f0fee9 yii
Step 4:
Move the extracted YII folder to root directory of your webserver (opt/lampp/htdocs/yii)
mv yii /opt/lampp/htdocs
Step 5:
Create a new folder as name appyii in root directory (appyii will contain yii framework files)
Step 6:
Apply YII framework to your appyii folder by yiic.php webapp file using php cli
mkdir appyii
php yii/framework/yiic.yiic.bat yiic.php
php yii/framework/yiic.php webapp /opt/lampp/htdocs/appyii/
Create a web application under '/opt/lampp/htdocs/appyii'? (yes|no) [no] :
Step 7:
Test that the installation has been done (http://localhost/appyii)
Note: if php command line interpreter not installed
PHP command line installation on Ubuntu Linux
The PHP command-line interpreter runs PHP scripts from the command line.
copy and paste the following command to your terminal
sudo apt-get install php5-cli
Steps to install YII PHP framework on ubuntu linux
Step 1:
Download the latest version of YII framework from http://www.yiiframework.com
Step 2:
Extract downloaded YII framework tar.gz file in same directory
cd Downloads/
tar -zxvf yii-1.1.14.f0fee9.tar.gz
Step 3:
Rename extracted folder as yii
mv yii-1.1.14.f0fee9 yii
Step 4:
Move the extracted YII folder to root directory of your webserver (opt/lampp/htdocs/yii)
mv yii /opt/lampp/htdocs
Step 5:
Create a new folder as name appyii in root directory (appyii will contain yii framework files)
Step 6:
Apply YII framework to your appyii folder by yiic.php webapp file using php cli
mkdir appyii
php yii/framework/yiic.yiic.bat yiic.php
php yii/framework/yiic.php webapp /opt/lampp/htdocs/appyii/
Create a web application under '/opt/lampp/htdocs/appyii'? (yes|no) [no] :
Step 7:
Test that the installation has been done (http://localhost/appyii)
Note: if php command line interpreter not installed
PHP command line installation on Ubuntu Linux
The PHP command-line interpreter runs PHP scripts from the command line.
copy and paste the following command to your terminal
sudo apt-get install php5-cli
PHP CMS Frameworks
July 31, 2014
Read more →
Joomla
Create Tabbed Content Module in Joomla
In this article, we are going to discuss about How to create a tabbed content module in Joomla. Creating the module with tabbed pane requires some knowledge of javascript. Joomla is an award-winning content management system (CMS), which enables you to build Web sites and powerful online applications. Many aspects, including its ease-of-use and extensibility, have made Joomla the most popular Web site software available. Best of all, Joomla is an open source solution that is freely available to everyone.
1) <div> tag is added for each Tabbed Menu, which is placed in one row in <table>. Provide Unique id to each tabbed menu.
2) Content to be displayed is also placed in <div> tag in another row of the <table>, with another id.
3) Click event is added to each tabbed menu in Javascript when the document is loaded using addEventListener() function for non IE and attachEvent() function for IE.
For non Internet Explorer add the below code
document.getElementById('divTitleTab1').addEventListener("click",titleDivTab1Func, false,true);
For Internet Explorer add the below code
document.getElementById('divTitleTab1').attachEvent("onclick",titleDivTab1Func);
titleDivTab1Func is the name of the function to be executed when click event occurs.
How to determine whether IE or non IE?
window.addEventListener returns true for non IE and false for IE.
if(window.addEventListener) {
}
else {
}
4) titleDivTab1Func function contains the code to be executed when user clicks on the tabbed menu. If user clicks on the tabbed menu its content should be displayed below it. It is done by setting innerHTML of the element with id of the content div.
document.getElementById("divContentTab").innerHTML = " you are under Tab 1";
5) Calling Javascript from helper.php
It is done by script() function of the JHtml class, which is used as shown below.
JHTML::_('script',"tabbed.js",JURI::base().'/modules/mod_tabbed/js/',true);
The last argument determines whether to load Mootools or not. Mootools is loaded if this argument is true. Here we have created 4 tabbed menu.
Files Required
1) mod_tabbed.php: This file is the entry point for the module. It will perform necessary initializations and call helper routine to collect necessary data and include the template which will display module output.
2) helper.php: This file contains the helper class which will collect necessary data to be used in the module from database or any other sources.
3) mod_tabbed.xml: This file contains the information about the module. This is the installation file for the module.
4) tmpl/default.php: This is the file used for displaying the module output.
5) js/tabbed.js: This file will contain necessary javascript code to be executed.
1) Creating file mod_tabbed.php with the below code
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
$hello = modTabbedHelper::getHello( $params );
require( JModuleHelper::getLayoutPath( 'mod_tabbed' ) );
?>
2) Creating file helper.php
This file contains the class as defined in mod_ varreq.php ,here it is modVarreqHelper class and contains function getHello(). The complete code of helper.php is
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class modTabbedHelper
{
static function getHello($params)
{
JHTML::_('script',"tabbed.js",JURI::base().'/modules/mod_tabbed/js/',true);
return 'Helper Tabbed Pane';
}
}
?>
3) Creating installation file mod_tabbed.xml
This file contains the information about the module. The complete code of mod_tabbed.xml is
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5" client="site" method="upgrade">
<name>tabbed</name>
<author>Larenge Kamal</author>
<version>1.7</version>
<description>Tabbed Pane! module.</description>
<files>
<filename>mod_tabbed.xml</filename>
<filename module="mod_tabbed">mod_tabbed.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
<filename>tmpl/logo1.bmp</filename>
<filename>js/tabbed.js</filename>
</files>
<config>
</config>
</extension>
4) Creating file tmpl\default.php
This file contains the output to be displayed by the module. This file has the same scope as that of the mod_tabbed.php. So the variables defined in mod_tabbed.php can be directly accessed in this file. '$hello' variable defined in mod_tabbed.php can be directly accessed here.
The complete code of tmpl\default.php is
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<html>
<body>
<table style="border:2px solid #E0E0E0; padding:0px; margin:0px" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td style="padding:0px; margin:0px" width="auto">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab1" class="mainTitle">
<b id="subTitle">Tab1</b>
</div>
</td>
<td style="padding:0px; margin:0px">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab2" class="mainTitle">
<b id="subTitle">Tab2</b>
</div>
</td>
<td style="padding:0px; margin:0px">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab3" class="mainTitle">
<b id="subTitle">Tab3</b>
</div>
</td>
<td style="padding:0px; margin:0px">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab4" class="mainTitle">
<b id="subTitle">Tab4</b>
</div>
</td>
</tr>
<tr>
<td colspan="4" style="padding:0px; margin:0px">
<div style="color: black;padding: 0px 0px 0px 10px;border:2px solid #E0E0E0" id="divContentTab" class="mainTitle">
here is tab content
</div>
</td>
</tr>
</table>
</body>
</html>
5) Creating file index.html common to all
The complete code of index.html is
<html><body bgcolor="#FFFFFF"></body></html>
6) Creating file js\tabbed.js
This file contains the javascript code. The complete code of js\tabbed.js is
window.addEvent("domready",function(){
if(window.addEventListener) {
document.getElementById('divTitleTab1').addEventListener("click",titleDivTab1Func, false,true);
document.getElementById('divTitleTab2').addEventListener("click",titleDivTab2Func, false,true);
document.getElementById('divTitleTab3').addEventListener("click",titleDivTab3Func, false,true);
document.getElementById('divTitleTab4').addEventListener("click",titleDivTab4Func, false,true);
}
else if(window.attachEvent) { //IE
document.getElementById('divTitleTab1').attachEvent("onclick",titleDivTab1Func);
document.getElementById('divTitleTab2').attachEvent("onclick",titleDivTab2Func);
document.getElementById('divTitleTab3').attachEvent("onclick",titleDivTab3Func);
document.getElementById('divTitleTab4').attachEvent("onclick",titleDivTab4Func);
}
});
function titleDivTab1Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab1").style.background = "#FFFFFF";
document.getElementById("divTitleTab2").style.background = "#F3F3F3";
document.getElementById("divTitleTab3").style.background = "#F3F3F3";
document.getElementById("divTitleTab4").style.background = "#F3F3F3";
oDiv.innerHTML = " you are under Tab 1";
}
function titleDivTab2Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab2").style.background = "#FFFFFF";
document.getElementById("divTitleTab1").style.background = "#F3F3F3";
document.getElementById("divTitleTab3").style.background = "#F3F3F3";
document.getElementById("divTitleTab4").style.background = "#F3F3F3";
oDiv.innerHTML =" You are in Tab 2" ;
}
function titleDivTab3Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab3").style.background = "#FFFFFF";
document.getElementById("divTitleTab1").style.background = "#F3F3F3";
document.getElementById("divTitleTab2").style.background = "#F3F3F3";
document.getElementById("divTitleTab4").style.background = "#F3F3F3";
oDiv.innerHTML ="Congratulations! You have a Joomla! site! Joomla! makes it easy to build a website just the way you want it and keep it simple to update and maintain.in tab3" ;
}
function titleDivTab4Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab4").style.background = "#FFFFFF";
document.getElementById("divTitleTab1").style.background = "#F3F3F3";
document.getElementById("divTitleTab2").style.background = "#F3F3F3";
document.getElementById("divTitleTab3").style.background = "#F3F3F3";
oDiv.innerHTML ="Joomla! is a flexible and powerful platform, whether you are building a small site for yourself or a huge site with hundreds of thousands of visitors. You are in Tab 4" ;
}
Now create the zip file of the folder 'mod_tabbed' which contains the following files.
The above zip file can now be installed using Joomla extension manager. After installing the module,' tabbed' module will appear in the module manager.
1) <div> tag is added for each Tabbed Menu, which is placed in one row in <table>. Provide Unique id to each tabbed menu.
2) Content to be displayed is also placed in <div> tag in another row of the <table>, with another id.
3) Click event is added to each tabbed menu in Javascript when the document is loaded using addEventListener() function for non IE and attachEvent() function for IE.
For non Internet Explorer add the below code
document.getElementById('divTitleTab1').addEventListener("click",titleDivTab1Func, false,true);
For Internet Explorer add the below code
document.getElementById('divTitleTab1').attachEvent("onclick",titleDivTab1Func);
titleDivTab1Func is the name of the function to be executed when click event occurs.
How to determine whether IE or non IE?
window.addEventListener returns true for non IE and false for IE.
if(window.addEventListener) {
}
else {
}
4) titleDivTab1Func function contains the code to be executed when user clicks on the tabbed menu. If user clicks on the tabbed menu its content should be displayed below it. It is done by setting innerHTML of the element with id of the content div.
document.getElementById("divContentTab").innerHTML = " you are under Tab 1";
5) Calling Javascript from helper.php
It is done by script() function of the JHtml class, which is used as shown below.
JHTML::_('script',"tabbed.js",JURI::base().'/modules/mod_tabbed/js/',true);
The last argument determines whether to load Mootools or not. Mootools is loaded if this argument is true. Here we have created 4 tabbed menu.
Files Required
1) mod_tabbed.php: This file is the entry point for the module. It will perform necessary initializations and call helper routine to collect necessary data and include the template which will display module output.
2) helper.php: This file contains the helper class which will collect necessary data to be used in the module from database or any other sources.
3) mod_tabbed.xml: This file contains the information about the module. This is the installation file for the module.
4) tmpl/default.php: This is the file used for displaying the module output.
5) js/tabbed.js: This file will contain necessary javascript code to be executed.
1) Creating file mod_tabbed.php with the below code
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'helper.php' );
$hello = modTabbedHelper::getHello( $params );
require( JModuleHelper::getLayoutPath( 'mod_tabbed' ) );
?>
2) Creating file helper.php
This file contains the class as defined in mod_ varreq.php ,here it is modVarreqHelper class and contains function getHello(). The complete code of helper.php is
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class modTabbedHelper
{
static function getHello($params)
{
JHTML::_('script',"tabbed.js",JURI::base().'/modules/mod_tabbed/js/',true);
return 'Helper Tabbed Pane';
}
}
?>
3) Creating installation file mod_tabbed.xml
This file contains the information about the module. The complete code of mod_tabbed.xml is
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5" client="site" method="upgrade">
<name>tabbed</name>
<author>Larenge Kamal</author>
<version>1.7</version>
<description>Tabbed Pane! module.</description>
<files>
<filename>mod_tabbed.xml</filename>
<filename module="mod_tabbed">mod_tabbed.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
<filename>tmpl/logo1.bmp</filename>
<filename>js/tabbed.js</filename>
</files>
<config>
</config>
</extension>
4) Creating file tmpl\default.php
This file contains the output to be displayed by the module. This file has the same scope as that of the mod_tabbed.php. So the variables defined in mod_tabbed.php can be directly accessed in this file. '$hello' variable defined in mod_tabbed.php can be directly accessed here.
The complete code of tmpl\default.php is
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<html>
<body>
<table style="border:2px solid #E0E0E0; padding:0px; margin:0px" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td style="padding:0px; margin:0px" width="auto">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab1" class="mainTitle">
<b id="subTitle">Tab1</b>
</div>
</td>
<td style="padding:0px; margin:0px">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab2" class="mainTitle">
<b id="subTitle">Tab2</b>
</div>
</td>
<td style="padding:0px; margin:0px">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab3" class="mainTitle">
<b id="subTitle">Tab3</b>
</div>
</td>
<td style="padding:0px; margin:0px">
<div style="background-color: #F3F3F3; color: black;font-weight: bold; padding: 0px 0px 0px 10px;cursor: pointer; border:2px solid #E0E0E0" id="divTitleTab4" class="mainTitle">
<b id="subTitle">Tab4</b>
</div>
</td>
</tr>
<tr>
<td colspan="4" style="padding:0px; margin:0px">
<div style="color: black;padding: 0px 0px 0px 10px;border:2px solid #E0E0E0" id="divContentTab" class="mainTitle">
here is tab content
</div>
</td>
</tr>
</table>
</body>
</html>
5) Creating file index.html common to all
The complete code of index.html is
<html><body bgcolor="#FFFFFF"></body></html>
6) Creating file js\tabbed.js
This file contains the javascript code. The complete code of js\tabbed.js is
window.addEvent("domready",function(){
if(window.addEventListener) {
document.getElementById('divTitleTab1').addEventListener("click",titleDivTab1Func, false,true);
document.getElementById('divTitleTab2').addEventListener("click",titleDivTab2Func, false,true);
document.getElementById('divTitleTab3').addEventListener("click",titleDivTab3Func, false,true);
document.getElementById('divTitleTab4').addEventListener("click",titleDivTab4Func, false,true);
}
else if(window.attachEvent) { //IE
document.getElementById('divTitleTab1').attachEvent("onclick",titleDivTab1Func);
document.getElementById('divTitleTab2').attachEvent("onclick",titleDivTab2Func);
document.getElementById('divTitleTab3').attachEvent("onclick",titleDivTab3Func);
document.getElementById('divTitleTab4').attachEvent("onclick",titleDivTab4Func);
}
});
function titleDivTab1Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab1").style.background = "#FFFFFF";
document.getElementById("divTitleTab2").style.background = "#F3F3F3";
document.getElementById("divTitleTab3").style.background = "#F3F3F3";
document.getElementById("divTitleTab4").style.background = "#F3F3F3";
oDiv.innerHTML = " you are under Tab 1";
}
function titleDivTab2Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab2").style.background = "#FFFFFF";
document.getElementById("divTitleTab1").style.background = "#F3F3F3";
document.getElementById("divTitleTab3").style.background = "#F3F3F3";
document.getElementById("divTitleTab4").style.background = "#F3F3F3";
oDiv.innerHTML =" You are in Tab 2" ;
}
function titleDivTab3Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab3").style.background = "#FFFFFF";
document.getElementById("divTitleTab1").style.background = "#F3F3F3";
document.getElementById("divTitleTab2").style.background = "#F3F3F3";
document.getElementById("divTitleTab4").style.background = "#F3F3F3";
oDiv.innerHTML ="Congratulations! You have a Joomla! site! Joomla! makes it easy to build a website just the way you want it and keep it simple to update and maintain.in tab3" ;
}
function titleDivTab4Func() {
var oDiv = document.getElementById("divContentTab");
oDiv.style.display = "block";
document.getElementById("divTitleTab4").style.background = "#FFFFFF";
document.getElementById("divTitleTab1").style.background = "#F3F3F3";
document.getElementById("divTitleTab2").style.background = "#F3F3F3";
document.getElementById("divTitleTab3").style.background = "#F3F3F3";
oDiv.innerHTML ="Joomla! is a flexible and powerful platform, whether you are building a small site for yourself or a huge site with hundreds of thousands of visitors. You are in Tab 4" ;
}
Now create the zip file of the folder 'mod_tabbed' which contains the following files.
- mod_tabbed.php
- index.html
- mod_tabbed.xml
- helper.php
- tmpl\default.php
- tmpl\index.html
- js\tabbed.js
The above zip file can now be installed using Joomla extension manager. After installing the module,' tabbed' module will appear in the module manager.
PHP CMS Frameworks
July 27, 2014
Read more →
YII
Steps to use AJAX form validation in YII Framework
In this article, we are going to discuss about How to implement the Ajax form validation in YII PHP Framework. Yii supports AJAX form validation, which essentially posts the form values to the server, validates them, and sends back the validation errors, all without leaving the page. It does this every time you tab out of a (changed) field.
Here's how Yii's AJAX validation works:
Step 1 :
Add the below code in your yii form declaration
<php $form = $this->beginWidget('CActiveForm', array(
'id'=>'lowercasemodelname-form', //not technically required but works w gii generated controllers
'enableAjaxValidation'=>true //turn on ajax validation on the client side
));
And have at least one form element with a matching error function:
<?php echo $form->textField($model, 'my_attribute'); ?>
<?php echo $form->error($model, 'my_attribute'); ?>
This makes Yii include the JQuery javascript library, as well as a Yii javascript file called jquery.yiiactiveform.js
Step 2:
In your controller file, in create or update, after you load the model, but before you load it from POST, call this
if(Yii::app()->getRequest()->getIsAjaxRequest()) {
echo CActiveForm::validate( array( $model));
Yii::app()->end();
}
Which is sligtly different than how Gii generates it, but no big diff. CActiveForm::validate() can take an array of models, which is not clear the way Gii does it.
Step 3:
Make sure that your model has at least one validation rule for the insert or update scenario. After you tab out of a changed field, Yii sends a standard AJAX POST to the server, and gets back a JSON response like this:
{"Field_id":["Validation error a"],"Another_field_id":["Validation error B"]}
which yii then plugs into the error field below your field.
Step 4:
When you use the $form->error() function, Yii adds a hidden div after your form element:
<div id="Model_attributename_em_" class="errorMessage" style="display:none"></div>
If that field has a validation error, then Yii sets the display to block, writes the validation error message to its innerHtml, and then you see the error. If it later validates, yii hides it again.
Step 5:
Yii will also add class names to the parent container of the field that it's validating. In most cases, this is a <div class="row">. When a form field is valid, it adds "success" class to the div - which makes it green. When it's invalid, it adds "error" class, which makes it red. It also quickly adds a "validating" class, which does nothing, but you can supply it yourself and change the look of a field while it's validating.
Here's how Yii's AJAX validation works:
Step 1 :
Add the below code in your yii form declaration
<php $form = $this->beginWidget('CActiveForm', array(
'id'=>'lowercasemodelname-form', //not technically required but works w gii generated controllers
'enableAjaxValidation'=>true //turn on ajax validation on the client side
));
And have at least one form element with a matching error function:
<?php echo $form->textField($model, 'my_attribute'); ?>
<?php echo $form->error($model, 'my_attribute'); ?>
This makes Yii include the JQuery javascript library, as well as a Yii javascript file called jquery.yiiactiveform.js
Step 2:
In your controller file, in create or update, after you load the model, but before you load it from POST, call this
if(Yii::app()->getRequest()->getIsAjaxRequest()) {
echo CActiveForm::validate( array( $model));
Yii::app()->end();
}
Which is sligtly different than how Gii generates it, but no big diff. CActiveForm::validate() can take an array of models, which is not clear the way Gii does it.
Step 3:
Make sure that your model has at least one validation rule for the insert or update scenario. After you tab out of a changed field, Yii sends a standard AJAX POST to the server, and gets back a JSON response like this:
{"Field_id":["Validation error a"],"Another_field_id":["Validation error B"]}
which yii then plugs into the error field below your field.
Step 4:
When you use the $form->error() function, Yii adds a hidden div after your form element:
<div id="Model_attributename_em_" class="errorMessage" style="display:none"></div>
If that field has a validation error, then Yii sets the display to block, writes the validation error message to its innerHtml, and then you see the error. If it later validates, yii hides it again.
Step 5:
Yii will also add class names to the parent container of the field that it's validating. In most cases, this is a <div class="row">. When a form field is valid, it adds "success" class to the div - which makes it green. When it's invalid, it adds "error" class, which makes it red. It also quickly adds a "validating" class, which does nothing, but you can supply it yourself and change the look of a field while it's validating.
PHP CMS Frameworks
July 23, 2014
Read more →
No more posts to load.
About this blog
PHPCMSFramework.com
Tutorials for WordPress, Laravel, Drupal, Joomla, Symfony & more — including AI-powered PHP guides. Publishing since 2012.
Trending posts
- CIBB - Basic Forum With Codeigniter and Twitter Bootstrap
- Steps to create a Contact Form in Symfony With SwiftMailer
- Build an AI-Driven personalisation engine in Joomla using User Behaviour data
- Creating and checking user session using CodeIgniter library
- Laravel and Prism PHP: The Modern Way to Work with AI Models
- Building a RAG System in Laravel from Scratch
- Build a WhatsApp AI Assistant Using Laravel, Twilio and OpenAI
- Build an AI Code Review Bot with Laravel — Real-World Use Case
- Build a RAG Pipeline Inside Joomla for Intelligent Site Search
- Symfony Framework - Introduction
