I am trying to submit a single form with multiple submit buttons. The form is submitted using Javascript. I am using the below api to create a table list with check box.
My controller file for creating the list is
$data[] = array(
'column-1' => '<form action="index.php/index/sign" method="post" id="form1">
<input type="checkbox" name="vehicle[]" value="Bike">I have a bike<br>
<input type="checkbox" name="vehicle[]" value="Car">I have a car<br>',
'column-2' => '<img src="' . $iconPath . '" /> image #',
);
$list = new pm_View_List_Simple($this->view, $this->_request);
$list->setData($data);
$list->setColumns(array(
'column-1' => array(
'title' => 'select',
'noEscape' => true,
'searchable' => true,
),
'column-2' => array(
'title' => 'Description',
'noEscape' => true,
'sortable' => false,
),
));
$tools = array (
array (
'title' => 'Add',
'class' => 'sb-activate',
'link' => 'javascript: submitform()',
),
array (
'title' => 'Delete',
'class' => 'sb-activate',
'link' => 'javascript: submitform1()',
),
);
In the above example you can see that there is multiple submit buttons which does adding and deletion respectively. Both after submitting will goes to action sign means the view file will be sign.phtml. The main index view file list is pasted below.
<script type="text/javascript">
function submitform()
{
document.forms["form1"].submit();
alert document.getElementById();
}
function submitform1()
{
document.forms["form1"].submit();
}
</script>
<?php echo $this->renderList($this->list); ?>
My issue is both the form submission redirects to the same action sign with only checkbox values. But I need to do different things for different form submission. So I need to differentiate add and delete in the sign action. Will I be able to send any parameter from javascript function to PHP sign function so that I can differentiate the button in PHP side.
Kindly don’t suggest normal html submit buttons with different names because I cannot do this in this api.
4
Answers
It would be possible to create a hidden element with the unique value on the fly. Try that.
You can have multiple submit buttons per form, just check the value in the post data.
HTML:
PHP:
—
EDIT: I read your question too quickly. Here’s a solution in JavaScript that may work for you.
HTML
JavaScript
Demo: http://jsfiddle.net/MK7u9/
you can create a input hidden element and on checkbox check/uncheck action you can assign value to that hidden element using Javascript and check the corresponding hidden element value on server side(php) to differentiate.