Jump to content

How to process multiple forms?


dca_steve

Recommended Posts

Hi all - I'm having difficulty with the processing of 3 forms on my web page. We'll call my 3 forms A, B, and C.

By default my page shows form A. The other 2 forms I have hidden via display:none

My issue is when I have form B or C showing. Once I hit submit, say within form B for example, I'd like this form to empty out all the fields, and remain visible for future entries/submittal of data. However, instead what happens is form A appears. How do I get form B to remain, allowing for a user to submit multiple entries of data without going back to form A?

 

This is a portion of my code at the very top of form A:

<div id="header_info" style="<?php if($_POST['form'] != "HeaderInfo") echo 'display: none';?>" >

<form id="HeaderInfo" method="post" action="annual_report_main.php" onsubmit="return validateHeader(this);">

 

Here's my entire code for form B:

<div id="branches_info" style=" <?php echo $display_branches; ?> ">

form method="post" action="annual_report_main.php" onsubmit="return validateBranches(this);">

<fieldset>

<p><strong>Branch Location</strong></p><br />

<label for="branch_address" class="long">Street Address:</label>

<input maxlength="50" type="text" name="branch_address" id="branch_address" value="<?php echo htmlentities($_POST['branch_address']);?>" /><br />

<div class="cleaner"></div>

<label for="branch_city" class="long">City:</label>

<input maxlength="20" type="text" name="branch_city" id="branch_city" value="<?php echo htmlentities($_POST['branch_city']);?>" /><br />

<div class="cleaner"></div>

<label for="branch_state" class="long">State:</label>

<input maxlength="2" type="text" name="branch_state" id="branch_state" value="<?php echo htmlentities($_POST['branch_state']);?>" /><br />

<div class="cleaner"></div>

<label for="branch_zip" class="long">Zip Code:</label>

<input maxlength="10" type="text" name="branch_zip" id="branch_zip" value="<?php echo htmlentities($_POST['branch_zip']);?>" /><br />

<div class="cleaner"></div>

<div class="content_onecolumn">

<input type="submit" name="Branches" value="Submit to Database" class="inputSubmit" />

</div>

<div class="content_onecolumn">

<input type="button" name="Finished" value="Finished" class="inputSubmit" />

</div>

</fieldset>

</form>

</div>

Link to comment
Share on other sites

how are you choosing which form to display?

and you're posting it with ajax...?

add "document.formName.reset();" to your validateHeader function to reset the form - where formName is the name of your form

and to have form B display after your submit form B, how are you choosing which form to display? is it posting the form and then reloading the page from scratch? if so use an $_GET variable in the URL to indicate which form it is... i.e. post formB to annual_report_main.php?form=b and then when you load that page, use

if (isset($_GET['form'])) {
switch ($_GET['form']) {
case "b":
echo "formB";
break;

case "c":
echo "formC";
break;

default:
echo "default Form A";
break;
}
}

Link to comment
Share on other sites

You probably want to use JavaScript - post the form to a hidden iFrame, and disable the form. Once the hidden iFrame page has loaded, enable the form to allow more posting. Et voila! Posted form with no refresh :D

Link to comment
Share on other sites

@joel24 - thx for the help.  I'm not using ajax, and yes it seems that my problem is that the form is reloading from scratch.  That's my main issue....what you wrote makes sense, I think I'll give that a shot!

 

@xyph - thank you as well for the reply!  I think I'll attempt what joel24 stated to see if I can get that to work.

 

Thanks again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.