Two submit buttons in one form - Stack Of Codes

Breaking

Ads

Tuesday 19 December 2017

Two submit buttons in one form

Two submit buttons in one form::

Multiple Submit Buttons in a form-



We can use more than one submit button in a single form.
We can give each input a different value and keep the same name or different name:

#Same name Like::
<input type="submit" name="action" value="Update" />
<input type="submit" name="action" value="Delete" />

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



#Diffent Name like::

<input type="submit" name="update_button" value="Update" />
<input type="submit" name="delete_button" value="Delete" />

PHP Code:

if (isset($_POST['update_button'])) {
    //update action
} else if (isset($_POST['delete_button'])) {
    //delete action
} else {
    //no button pressed

}

No comments:

Post a Comment

Topics

PHP (27) CodeIgniter (22) SQL (4) Facebook (3) HTML (3) Blogger (2) Constructor (2) Destructor (2) Google (2) How to (2) Aadhaar (1) Agent (1) Browser (1) CSS (1) Cakephp (1) Constants (1) India (1) Ip address (1) JS (1) Jquery (1) Meta Tags (1) Robots (1) Scraping Data (1) escape_str (1) htaccess (1) iS mobile (1) javascript (1) mysqli (1)