PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] Setting ID attribute of input field when using ActiveField in Yii2?

 January 20, 2022     php, yii, yii2     No comments   

Issue

I'm trying to set a custom id for an input field whilst using ActiveField in Yii2.

I tried the below, but it instead set the id of the field container instead of the input field itself.

$form->field($model, 'some_id', ['options' => ['id' => 'some_id']])->hiddenInput(['value' => $some_id])->label(false);

Is there a way I can set the id attribute of the input field itself?

I noticed the inputOptions option, but this seems to control the setting for all the fields, so unsure how it works exactly with the selectors etc.


Solution

Just add id key to options array you've already passed in to hiddenInput method

$form->field($model, 'some_id')->hiddenInput(['value' => $some_id, 'id' => 'some_id'])->label(false);


Answered By - Tony
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing