make masks without connection with models

Hello again,

My question is about a simple thing…

I have to put mask in a textfield, but, (for a reason for make a update in a table and this field needs a treatment before enter in the table) without connect to the model as shows the example…

Using connection with a model, i have to make this…


<div class="row">

            <?php echo $form->labelEx($contact_model,'res_telephone'); ?>

            <?php $this->widget('CMaskedTextField', array(

                'model' => $contact_model,

                'attribute' => 'res_telephone',

                'mask' => '(99)9999-9999',

                'htmlOptions' => array('size' => 15)

            )); ?>

            <?php echo $form->error($contact_model,'res_telephone'); ?>

        </div>

but, this don’t solve my problem and i have to use the follow example…


<div class="row">

            <label>Telefone Celular</label>

            <input size="15" maxlength="13" id="Tel_resid" type="text" />

        <!--I have to use the mask (99)9999-9999 here-->

</div>



have some function in yii or i have to use javascript to solve it??

Thanks in advance…

use ‘name’ instead of ‘model’ and ‘attribute’, like




$this->widget('CMaskedTextField', array(

 'name' => 'tel_res',

 'mask' => '(99)9999-9999',

));



Ok but, when i’ll use the information in the model (in this case this information is been used in another module… and i still have to save it…) i just use ‘tel_res’ to get the right information? (sorry i stay shocked when i see a solution using just yii mode ^^ is my first time using yii as you can see…)

Example:

i’ll have to take off the mask to use in my table in database…

so, i call in controller the content in field like this…


if (!empty ($_POST["tel_resid"]))

            {

                $contact_model->information = str_replace("(", "", $_POST["tel_resid"]); 

                $contact_model->information = str_replace(")", "", $_POST["tel_resid"]); 

                $contact_model->information = str_replace("-", "", $_POST["tel_resid"]); 

            }

and when i will save, i’m trying to use this:


if (!empty ($_POST["tel_resid"]))

                        {

                            $contact_model->system_user_id = $user_model->id;

                            $contact_model->contactType = 1;

                            $contact_model->information = $_POST["tel_resid"];

                        }

(must this is extremely wrong, i know, but i’m little bit confused with how to save this information…)

i expect that you can understand what i’m talking about… thanks in advance.

Yea, pretty much it

to simplify, use it like this in your controller:




if (isset($_POST["tel_resid"])){

 $contact_model->system_user_id = $user_model->id;

 $contact_model->contactType = 1;

 $contact_model->information = str_replace(array("(",")","-"), "", $_POST["tel_resid"]);

 if($contact_model->save()){

  echo "Data saved!!";

 }

}

and you done

or use in the model




function beforeValidate(){

  if(!empty($this->information)){

 	$this->information=str_replace(array("(",")","-"), "", $this->information)   

  }

}



I solved, now he saves and makes everything right… except when i have to update he just go adding and adding… i make some changes using the idea who you pass…


if (isset($_POST["tel_resid"]) && !empty($_POST["tel_resid"]))

            {

                $contact_model->isNewRecord = true;

                $contact_model->system_user_id = $user_model->id;

                $contact_model->contact_type_id = 1;

                $contact_model->is_public = true;

                $contact_model->information = $_POST["tel_resid"];

                $contact_model->save(false);

            }