javascript - radio button list with text option cakephp -


i new cakephp. need make form radio buttons , last 1 "other" user can type in answer in text box.

is there way formhelper can that's built in?

one way going create radio list , text field. when "other" selected javascript show text field. don't understand how use other variables besides fields in database. how 1 create variable model can accessed view , value returned processing?

for model have:

class user extends appmodel {      /**      * display field      *      * @var string      */     public $displayfield = 'title';     var $sourceother = ' ';     var $passwordrepeat = ' ';       public function beforesave($options = array()) {         if (isset($this->data[$this->alias]['password'])) {             $this->data[$this->alias]['password'] = sha1(                     $this->data[$this->alias]['password']);         } //        $this->data[$this->alias]['created']= caketime::gmt(); //        $this->data[$this->alias]['updated']= caketime::gmt();         $this->data[$this->alias]['username']= $this->data[$this->alias]['email'];          return true; 

in view have

echo $this->form->input('mobilephone',array(     'label'=>'mobile or fixed phone no spaces')); echo $this->form->input('alternatephone'); echo $this->form->input('leadsource', array(     'options'=>array('google'=>'google','onlinead'=>'online ad',             'printed media'=>'printed media','letterdrop'=>'letter drop',             'other'=>'other (specify text)'),     'empty'=>'(choose one)'));  echo $this->form->input($this->sourceother); 

...but doesn't sourceother, variable in model. how data view (the text box) user model beforesave can it?

thanks.

thanks.

sorted out after reading "cake php application development". works cake 2.x , 1.2 (as used in book).

in view put:

echo $this->form->input('sourceother'); 

then in model can access variable with:

$this->data['user']['sourceother']; 

for example, use save "other" text field in beforesave:

public function beforesave($options = array()) {     if (isset($this->data[$this->alias]['password'])) {         $this->data[$this->alias]['password'] = sha1(                 $this->data[$this->alias]['password']);     }     $this->data[$this->alias]['username'] = $this->data[$this->alias]['email'];      $this->data[$this->alias]['activation'] = md5(uniqid(rand(), true));      if ($this->data[$this->alias]['leadsource'] == 'other') {         $this->data[$this->alias]['leadsource'] =                 $this->data['user']['sourceother'];     }     return true; } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -