I’ve got the following Codeigniter code to display a form, with two image submit buttons. I need to know which button has been clicked by the user. Normally I just reference the name or value that is passed through, but nothing is passed from these buttons. All other fields/textboxes etc.. on the form pass through ok, but nothing from these buttons….
…. what am i missing? I’ve been pondering this for a couple of hours and no help from the net either!
Ta
<?
$attributes = array('id' => 'formname','name' => 'formname');
echo form_open('processform',$attributes);
$btn_input = array(
'subtype' => ''
);
echo form_hidden($btn_input);
$btn_search = array(
'type' => 'image',
'src' => '/graphics/button1.gif',
'id' => 'button1',
'name' => 'button1',
'value' => 'button1'
);
?>
<div id='1stbutton' style='text-align: center'>
<? echo form_input($btn_search);?>
</div>
<?
$btn_search = array(
'type' => 'image',
'src' => '/graphics/button2.gif',
'id' => 'button2',
'name' => 'button2',
'value' => 'button2'
);
?>
<div id='2ndbutton' style='text-align: center'>
<? echo form_input($btn_search);?>
</div>
<? echo form_close(); ?>
I had a similar issue (with Zend though)!
The thing is, the browser does not pass the “value” when input type=image.
to check wich button was clicked you could still reference the button by adding “_x” or “_y” to your button name (Ex ‘Button2_x’)and check the $_Post array against this.
If you need a look here.Same Issue Explained in Codeigniter forum