dca_steve Posted August 2, 2011 Share Posted August 2, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/243637-how-to-process-multiple-forms/ Share on other sites More sharing options...
joel24 Posted August 2, 2011 Share Posted August 2, 2011 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/243637-how-to-process-multiple-forms/#findComment-1250962 Share on other sites More sharing options...
xyph Posted August 2, 2011 Share Posted August 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243637-how-to-process-multiple-forms/#findComment-1250963 Share on other sites More sharing options...
dca_steve Posted August 2, 2011 Author Share Posted August 2, 2011 @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! Quote Link to comment https://forums.phpfreaks.com/topic/243637-how-to-process-multiple-forms/#findComment-1250975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.