conflicting id from multiple forms from same model

Edit: topic should read "active forms"

I’ve searched all over and can’t find a solution. I found this bug report that says I should just be able to change the id to fix the issue.

I have a login form on a page that also has a signin form.

They both use a users model with difference scenarios and have password fields with the same ID.

I’ve tried change changing the “id” for the login field in the htmlOptions array, but then it doesn’t react to any changes. It seems the js is fixed to work with a specific name.

I looked at all the extra options and I found the inputComtainer but that only seems to be for the error() method and if I change the id for the textField and set the inputContainer for the error() to that id, it doesn’t seem to have any effect. It doesn’t validate on change.


I still can’t figure out a proper way to do this…

OTOH, I did kind of hack it together.

I used tabular notation for the attributes in the model. But the CActiveForm ajax validation doesn’t quite work with them, so I went:

      $_POST['User'] = $_POST['User'][0];

      $response = CActiveForm::validate($model);

      echo str_replace("User_","User_0_",$response);

Which is really hacky… I’d like a better method, but this way at least the login won’t interfere with any other forms (as long as I don’t actually need tabular input for that model)

I have the same problem, but with the textField.

For example, in the following code the id for the vehicleID field will always be in the format: (class name of the model)_vehicleID.

Is there a way to change the id of the textField in the form?

Thank you!

<?php $form=$this->beginWidget(‘CActiveForm’, array(






)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;

&lt;div class=&quot;row&quot;&gt;

	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'vehicleID'); ?&gt;

	&lt;?php echo &#036;form-&gt;textField(&#036;model,'vehicleID'); ?&gt;

	&lt;?php echo &#036;form-&gt;error(&#036;model,'vehicleID'); ?&gt;


<?php $this->endWidget(); ?>

You can change the ids. textField etc. take a list of HTML Options as the third parameter. So do something like:

$id = array();

$id['id'] = 'my_new_id';

<?php echo $form->labelEx($model,'vehicleID', $id); ?>

<?php echo $form->textField($model,'vehicleID', $id); ?>

<?php echo $form->error($model,'vehicleID'); ?>

This way, you can also add classes etc. to the html element.

I had the same problem, conflicts form input between same models.

My solution is simple :

  1. Add a hidden field which contains ID of model.

  2. Check $_POST and ID in controller/action and … do whatever you like!

Thought I’d share my solution, in case it helps someone.

Quick background: I have a navbar with a popup login form. In some cases (i.e. if you’re already on the login page itself) there’s a second, main login form that uses the same form model class – and thus was creating conflicting input IDs.

My main form model was a class called LoginForm. So I just created a second form model that extended that, but with no additional functionality:

class LoginForm2 extends LoginForm {}

And I used that class when creating the model for my secondary (popup) login form. Then in my controller action, I just did this:

if(isset($_POST['LoginForm2'])) {

     $_POST['LoginForm'] = $_POST['LoginForm2'];