Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:25:14+00:00 2026-05-18T23:25:14+00:00

I have 2 submit buttons and want to perform different actions for each submit

  • 0

I have 2 submit buttons and want to perform different actions for each submit button . Here I want to set the form fields which can be done only in form_alter(). Can anyone suggest how to check for multiple submit buttons in the form_alter() function?

I have used

function myform_form_submit($formID, &$form_state) {
if($form_state['clicked_button']['#value'] == $form_state['values']['submit_one'])    //if button 1      is clicked
     $form_state['redirect'] = 'mypath/page_one';   //redirect to whatever page you want
 else if($form_state['clicked_button']['#value'] == $form_state['values']['submit_two'])  /if button      2 is clicked
    $form_state['redirect'] = 'mypath/page_two';
 }

but this does not work

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:25:15+00:00Added an answer on May 18, 2026 at 11:25 pm

    The best thing to do if you have two submit buttons on a form and want them to do different things, is to create a different submit function for each button, and connect them up. One of the nice things about the FormAPI is that it automatically links the form with the submit handler for you, but if you have two submit buttons you want to go somewhere new.

    So your form code is likely to contain:

    $form['submit_one'] = array(
      '#type' => 'submit',
      '#value' => t('Submit One'),
      '#submit' => array('my_module_form_submit_one'),
    );
    $form['submit_two'] = array(
      '#type' => 'submit',
      '#value' => t('Submit Two'),
      '#submit' => array('my_module_form_submit_two'),
    );
    

    But I don’t know what you mean by form_alter() – there’s no reason to use a form alter of any sort.

    Edit: As came up in the comments – if you need different validation functions for the two buttons, you can also include '#validate' => array('my module_form_validate_one') and '#validate' => array('my module_form_validate_two') in the respective button arrays. But it’s not required, and if the standard form validation function works fine then go with that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I have 2 buttons and each button to perform a different post
I have a form on an HTML page with multiple submit buttons that perform
I have 3 buttons in a form. One of them is the submit button.
Say I have textboxes, dropdownlists and submit buttons. They are all inline-elements. Which means
I have a listbox on an HTML form with a Submit button. The listbox
Is it possible to determine which submit button was used? I have a confirmation
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I have multiple check boxes. When the Submit button is clicked I want to
i load a form into a jquery ui dialog. i have a submit button
When I click the purchase button for the form I want the buttons text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.