I do not seem to be able to find an answer for this, though likely I am looking at the wrong thing. I currently have a Yii application where I am able to create accounts and store peoples data. One such piece of data is a persons IBAN number. Currently I have a single text input where people can type the country code and the 22 digits necessary. I am then able to validate this and error or save accordingly. One thing I would like to do is to be able to have a split input box. In a single input an Iban appears like so: ES0012345678912345678912
I would like to split it like so: ES00 1234 5678 91 2345678912
This makes it much more user friendly and easy to read. I can certainly change the way it looks on the view but when editing I would like to have five input boxes in a single row, one takes 4, the next one 4 characters, the next one 4 etc. An example of what I mean:
Can someone please point me in the direction of how this is achieved. Is there a type of split input I can use, or do I need to create 5 separate inputs and simply join them on submission and validate from here? The ability to simply split the saved entry across these 5 boxes would be much easier.
Many Thanks
As a suggestion, if you use a model, simply add your attributes like below:
Class ModelName extends CActiveRecord {
public $ibanNumber;
public $ibanNumberPart1;
public $ibanNumberPart2;
public $ibanNumberPart3;
public $ibanNumberPart4;
public function beforeValidate(){
if(parent::beforeValidate()){
$this->ibanNumber=$this->ibanNumberpart1.$this->ibanNumberPart2 ...
return true;
}
}
//then write rules and so on
...}
By adding $ibanNumberPart1..4 properties to your model, it will know all of them as model attribute. So you can add 4 fields in your view with name ibanNumberPart1
and so on. It is also possible to write validations rules for each attribute. For example:
public function rules(){
return array(
array('ibanNumberPart1','required'),
array('ibanNumberPart1','numerical','integerOnly'=>true),
);
}
By this, you split your input into 4 parts, and finally you have all of them into 1 field called $ibanNumber
.