2 submit buttons

Post your questions and problem reports here.

2 submit buttons

Postby kohle » Wed Nov 16, 2016 4:18 pm

Hi,
I have a form where I use 2 submit buttons :
Code: Select all
<input type="submit" name="action" value="Update" />
<input type="submit" name="action" value="Delete" />



Code: Select all
Then in the code check to see which was triggered:

if ($_POST['action'] == 'Update') {
    //action for update here
} else if ($_POST['action'] == 'Delete') {
    //action for delete
} else {
    //invalid action!
}



How must I change this using button/menu maker ?
I have defined a button like this and use onclick. With 1 button I can use a hidden field, but when I want 2 buttons ? :
Code: Select all
<div id="mbsubmitebul_wrapper">
              <ul id="mbsubmitebul_table" class="mbsubmitebul_menulist css_menu">
              <li><a href="" onclick="document.getElementById('form1').submit();return false;">
                  <div class="buttonimg buttonimg_31" style="width: 76px; background-image: url('mb_speichern.png')">Speichern</div></a></li>
              </ul>
            </div>


But it works only with on Button. I must pass some kind the value, so I can recognize the button what was pushed.
kohle
 
Posts: 4
Joined: Wed Nov 16, 2016 4:09 pm

Re: 2 submit buttons

Postby Aivars » Wed Nov 16, 2016 4:36 pm

This is a general HTML/Javascript question but I'll try to help you.

Here's one way to do it:

Code: Select all
<input type="hidden" name="hid_action" id="hid_action" value="" />
<input type="submit" name="action" value="Update" />
<input type="submit" name="action" value="Delete" />


Code: Select all
if ($_POST['action'] == 'Update' || $_POST['hid_action'] == 'Update') {
    //action for update here
} else if ($_POST['action'] == 'Delete' || $_POST['hid_action'] == 'Delete') {
    //action for delete
} else {
    //invalid action!
}


Code: Select all
...
<a href="" onclick="document.getElementById('hid_action').value="Update";document.getElementById('form1').submit();return false;">
...
<a href="" onclick="document.getElementById('hid_action').value="Delete";document.getElementById('form1').submit();return false;">
...
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
 
Posts: 2453
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: 2 submit buttons

Postby kohle » Wed Nov 16, 2016 8:42 pm

Thanks alot.
kohle
 
Posts: 4
Joined: Wed Nov 16, 2016 4:09 pm


Return to Easy Button & Menu Maker Support

Who is online

Users browsing this forum: No registered users and 10 guests

cron