CActiveForm ajaxValidation not posting imageButton

I have come across an issue with CActiveForm ajaxValidation (and clientValidation) when used in conjunction with imageButton.

It seems that the imageButton is not actually being posted. Here is a sample markup:


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

	'id'=>'booking-form',

	'enableAjaxValidation'=>true,

	'enableClientValidation'=>false,

	'clientOptions'=>array(

		'validateOnChange'=>false,

		'validateOnSubmit'=>true,

	),

)); ?>


<div class="row">

<!-- form fields -->

</div>


<div class="row buttons">

	<?php echo CHtml::imageButton('images/confirm-button.png', array('name'=>'confirm')); ?>

</div>


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

In my controller action I commented out the "save and redirect" functionality so that the form can get posted to the same page and I can do a print_r($_POST).

I found that all the model variables are being posted in their array, but the imageButton does not get posted. If I disable ajaxValidation, it works as expected.

Can anyone else replicate this issue?

(BTW I need the imageButton to be posted because I have multiple imageButton’s on the page and I need to check which one was clicked.)

The image input type doesn’t send the name on its own, but appends the x and y coordinates of the click. Try experimenting with it here:

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_src

You’ll need to add the name attribute.

Confirming whether a button was clicked may just be a matter of looking for the attribute buttonname.x .

Yes I’m aware of that, however the problem is the input isn’t being posted at all (not even with the x/y co-ordinates).

Anybody able to replicate the problem, is it a bug or am I doing something incorrectly?

Where do you try to do print_r() ?

I just added these lines




		if(!empty($_POST))

		{

			echo "<pre>";

			print_r($_POST);

			echo "</pre>";

		}



at the beginning of actionCreate() - before the $model = new <my model>;

and when I click the image I get on the screen something like




Array ( 	

   [confirm_x] => 6 	

   [confirm_y] => 10 

)

Hi mdomba,

You’ve definitely enabled ajaxValidation (in view and controller)?

I put the same print_r() code at the beginning of my action and I still don’t get the imageButton posted.

I’m using Yii 1.1.11 / Windows 7 / Firefox 14

Yes I did… but I did not check the ajax response…

Yes the imageButtons are not sent with the ajax request, problem is in the jQuery submit selector - it does not take into account <input type="image" …>

I created a github issue for this - https://github.com/yiisoft/yii/issues/1242