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 8127423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:31:34+00:00 2026-06-06T07:31:34+00:00

I have two forms, and so two different submit buttons, for one page (page

  • 0

I have two forms, and so two different submit buttons, for one page (page used for adding staff members to company db).

The first submit deals with submitting a username (name and faculty automatically filled in through a command line program). Obviously, I want to keep this information and display it to the user while they are filling out the information required in the second form. This works fine.

The problem is if there is an error in the second form. The addition fails and an error message displays but all the information from the first form is wiped out.

The session variables below are set if the first form is submitted (with no errors):

$_SESSION['name'] = $info['displayName'];
$_SESSION['faculty'] = $info['ou']; 
$ownerId = trim(mysql_prep($_POST['ownerId']));
$_SESSION['ownerId'] = $ownerId;

But when these variables are wiped out if the second form is submitted. My understanding is that this happens because the first form is not technically submitted anymore. But, then again, isn’t that the point of session variables — not to be wiped out?

EDIT: Maybe it would be helpful to add that I unset all the session variables, but ONLY if the second form was submitted with no errors. Although I don’t think this is very relevant

  • 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-06-06T07:31:35+00:00Added an answer on June 6, 2026 at 7:31 am

    There are 2 approaches I could think of

    if($POST['form_name'] == 'form1')
    {
       //set my session variables
    }
    else  //for the second form
    {
      //do something else
      //then session is intact
    }
    

    I used to put an hidden field in my form to store the name of the form. Some use the name of the submit button.

    The other approach is repopulate the other form which am still thinking of how to do it without using one button for the two form

    <form name="form1" action="POST" action="xxx">
        <input type="text" values="<?php print($_POST['firstform_val_1']) ?>" name="val_1" />
    </form>
    
    
    <form name="form2" action="POST" action="xxx">
      //these hidden fields preserve the formal values and make sure they are reposted in this second form
      <input type="hidden" name="firstform_val_1" value="<?php print($_POST['firstform_val_1']) ?>" />
      <input type="hidden" name="firstform_val_2" value="<?php print($_POST['firstform_val_2']) ?>" />
    
      <input type="text" name="secondform_val1" />
      <input type="submit" name="form2" />
    </form>
    

    That is the idea. I just got this from upstair, not tested. In the first form, the previous value is re-populated by the values duplicated in the hidden fields of the second form

    Good Luck

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

Sidebar

Related Questions

I have two submit buttons in a form which has different values, one to
I have two submit buttons in one form. I want to call different actions
I have two different forms on my home page: one for logins and one
I have two forms on one page and want to have the input boxes
I have a django form with two different submit buttons, on the view where
I have a form with two different submit buttons. I take a different action
I have a Django project that, on one page, has multiple forms (in different
I have a page with several forms. I am trying to submit one of
I have a template page expecting two forms. If I just use one form,
I have two submit buttons with the same name but submitting different values in

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.