countrygyrl Posted May 20, 2010 Share Posted May 20, 2010 I have a page that I have two forms on, both forms have error processing, I am banging my head against the wall and I need some fresh eyes. It's probably something simple but I can't wrap my head around it. What I need is an if statement that says only show the num_errors and the errors themselves if this form has been submitted or something? <? if($form->num_errors > 0){ echo "<p><span class=\"error\">".$form->num_errors." error(s) found</span><br />"; echo "<p><span class=\"error\">".$form->error("user2")."</span><br />"; echo "<span class=\"error\">".$form->error("pass2")."</span></p>"; } ?> <form action="process.php" method="POST"> <p><label for="user2">Username:</label><input type="text" name="user2" maxlength="30" size="10" value="<? echo $form->value("user2"); ?>" /></p> <p><label for="pass2">Password:</label><input type="password" name="pass2" maxlength="30" size="10" value="<? echo $form->value("pass2"); ?>" /></p> <p><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?> /> Remember me <input type="hidden" name="sublogin" value="1" /> <input type="submit" value="Login" /></p> <p class="legal">[<a href="forgotpass.php">Forgot Password?</a>]</p> </form> Link to comment https://forums.phpfreaks.com/topic/202330-2-forms-1-page-error-processing/ Share on other sites More sharing options...
Yucky Posted May 20, 2010 Share Posted May 20, 2010 I usually stick all errors into an array and then do something along the lines of: if (count($errorArray)) { foreach ($errorArray as $key => $value): HTML here. endforeach; Works like a charm for me, and it'd seemingly allow you to do what you want with multiple forms without hassle. Link to comment https://forums.phpfreaks.com/topic/202330-2-forms-1-page-error-processing/#findComment-1060910 Share on other sites More sharing options...
countrygyrl Posted May 20, 2010 Author Share Posted May 20, 2010 Unfortunately, that won't work for me because the error messages for the two different forms show up in two different areas of the page. I am looking for something like this, but of course this doesn't work lol if (sublogin == 1) { if($form->num_errors > 0){ echo "<p><span class=\"error\">".$form->num_errors." error(s) found</span><br />"; echo "<p><span class=\"error\">".$form->error("user2")."</span><br />"; echo "<span class=\"error\">".$form->error("pass2")."</span></p>"; } } Link to comment https://forums.phpfreaks.com/topic/202330-2-forms-1-page-error-processing/#findComment-1060918 Share on other sites More sharing options...
Yucky Posted May 20, 2010 Share Posted May 20, 2010 You could wrap them in if statements to test for which form was submitted. If you give the submit buttons for both the forms different values, you'll be able to test pretty easily. if ($_POST['Submit'] == "form1") { etc } Link to comment https://forums.phpfreaks.com/topic/202330-2-forms-1-page-error-processing/#findComment-1060925 Share on other sites More sharing options...
countrygyrl Posted May 20, 2010 Author Share Posted May 20, 2010 Ok I got it, I gave a value to a session variable if there were errors on that particular form and only ran the php error display code if that value was equal to 1 and then unset the session variable as soon as the code was displayed, thanks for your help. Link to comment https://forums.phpfreaks.com/topic/202330-2-forms-1-page-error-processing/#findComment-1061125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.