Tuesday, August 7, 2012

Url Parsing In Jquery

Get Url(domain) parameter using jquery function.
In below code, I wrote one function called getUrlVars().
Using this function you can get requesting parameter value. 
If parameter not found., It will return undefined response
It was working for me good. 
    var ID= getUrlVars()["id"];
    if(ID==undefined){
        ID='';
    }    
    function getUrlVars() {
        var vars = {};
        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
                     function(m,key,value) {
                       vars[key] = value;
                     });
        return vars;
    }


Url:http://mydomain.com/index.php?id=1

In js:    var ID= getUrlVars()["id"];

Output: 
ID=1

In js:    var ID= getUrlVars()["name"];

Output: 
ID=undefined
Read More...

Thursday, July 26, 2012

Many To Many Search in Table

User Table

UseridUsername
1Name1
2Name2
3Name3

Subscription Table

SubIdSubName
1Subname1
2Subname2

User_Subscription Table

UseridSubId
11
12
22
31

Many To Many Search Format1

How Many users Subscripted in 1 or 2

Many To Many Search Format2

How Many users Subscripted in 1 and 2
Read More...

Ajax Submit Button in Yii

This source to Apply the AjaxSubmitButton instead of submitButton in yii


Yii CHtml ajaxSubmitButton I added ajaxsubmitbutton instead of submitButton. When i click the submit button I will send form data through ajax post and i will do controller work for insert and i render the listdata using CHtml::listData() and i will set the response value to eventlist dropdownlist. So I am updating the event list without page refresh using ajaxsubmitbutton of yii
For More Details www.bsourcecode.com
Read More...

Tuesday, July 24, 2012

Yii Hint For Form Radio Button

When you select the radio button, Form will get submit action

Read More...

Monday, July 23, 2012

insert data into Dropdownlist by ajax request in yii

In view.php
-----------------


In controller.php
-----------------

Read More...

Thursday, July 19, 2012

Yii ajax request and json response array


In view.php


In Controller.php

Read More...

Wednesday, July 18, 2012

Yii Model Rules

This tutorial will help you to understand the yii model rules, user defined functions. In yii rules function I added code (of yiiframework) for unique,email,password comparison, date, phone number, trim etc.. I created user functions for alphanumeric password validation, phone number or mobile number requirements validation.
<?php
class Mytable extends CActiveRecord{

public static function model($className=__CLASS__){
return parent::model($className);
}

public function rules()
{
return array(
array('status', 'numerical', 'integerOnly'=>true),
array('username, password, firstname, lastname, contactno', 'length', 'max'=>45),
array('gender, newsletter', 'length', 'max'=>1),

/** Username validation in yii model **/
array('username', 'match' ,'pattern'=>'/^[A-Za-z0-9_]+$/u',
'message'=> 'Username can contain only alphanumeric characters and hyphens(-).'),

/** Set scenario for model. Yii Scenario will help you to change dynamic validation using controller.
$model=Mytable::model()->findByPk($id); //(OR) $model = new Mytable();
$model->setScenario('updateuser'); // (OR) $model->scenario ='updateuser';
**/ 
array('username','unique','on'=>'updateuser'),


/** EMAIL VALIDATION **/
//Yii M odel Rules For Email
array('emailid', 'length', 'max'=>225),
array('emailid', 'email'),

/** PASSWORD VALIDATION **/
//Yii Model Rules For Password Confirm
array('password', 'compare', 'on'=>"confirmpassword", 'compareAttribute'=>'password'),

//Yii Model alphanumeric password validation
array('password','passwordalphanumeric','on'=>'changepassword'), 

/** DATE VALIDATION **/
//Yii Model Rules For Date Format
array('dob', 'type', 'type' =>'date', 
'message' => '{attribute}: is not a date!', 'dateFormat' => 'yyyy-MM-dd'),

/** SIMPLE PHONE NUMBER VALIDATION **/
//Yii Model Rules For Entering Mobile Or Phone Number
array('stdcode,phoneno,mobileno', 'numerical', 'integerOnly'=>true),

//Validation without STD CODE NUMBER
array('phoneno,mobileno','my_required'),
//(OR)
//Validation with STD CODE NUMBER
array('phoneno,mobileno,stdcode','my_required'),

/** TRIM DATA BEFORE SEND TO DATABASE **/
//Yii Model Rules For Trimming Data
array('username', 'filter', 'filter'=>'trim'),

/** UNIQUE VALIDATION **/
//Yii Model Rules For Unique data
array('username', 'unique'),
/** Yii Float Number VALIDATION **/
array('ratio', 'match', 'pattern'=>'/^[0-9]{1,3}(\.[0-9]{0,2})?$/'),

/** Value In Condition **/
array('status', 'in', 'range'=>array(1,2,3)),

);
}



// BeforeValidate function in yii rules
public function beforeValidate() {
       if (!$this->phoneno && !$this->mobileno) {
            $this->addError('mobileno', 'Enter Mobile Number Or Phone Number');
        }
        return parent::beforeValidate();
    }

// User defined function 
//Validation without STD CODE NUMBER
public function my_required($attribute_name,$params){
     if(empty($this->phoneno) && empty($this->mobileno)){
               $this->addError($attribute_name,
                 'Please enter Telephone number or Mobile number');
     }
}

//Validation with STD CODE NUMBER
public function my_required($attribute_name,$params){
     if(empty($this->phoneno) && empty($this->mobileno)){
             $this->addError('phoneno',
                 'Please enter Telephone number or Mobile number');
     }else if(!empty($this->phoneno) && $this->stdcode==''){
             $this->addError('stdcode','Please enter STD number');
     }
}

// Check password with alphanumeric validation
public function passwordalphanumeric($attribute_name,$params){
     if(!empty($this->password)){
          if (preg_match('~^[a-z0-9]*[0-9][a-z0-9]*$~i',$this->password)) {
                // $subject is alphanumeric and contains at least 1 number
     } else { // failed
          $this->addError($attribute_name,'Please enter password with digits');
     } 
}
}
}
?>
Read More...

Monday, July 16, 2012

Yii hint for CGridview

Hint1:

Read More...

Yii CListview pager

We can change yii default pager text for CListview 

Read More...

Yii Pagination For CActiveDataProvider

    
Read More...