mattrd Posted October 13, 2008 Share Posted October 13, 2008 I have a form that will refresh once it is submitted. There are two fields that if left blank will cause an error message and display the form again. If they submit the form correctly it will refresh the page and display a thank you message. But the form displays again. I don't want the form to display if they filled it out correctly. I don't know how to do this. I have an include_once that displays the form now. this is just because if I don't have it it won't show up at all. This is my code, can anyone please help me? thank you. <?php # Define the page title $page_title = 'Post to Journal'; # Include header and navigation menu include('includes/header.php'); include('includes/left_nav_admin.php'); include('includes/greenbox.php'); # Define necessary variables $months = array(1 => 'January','February','March','April','May','June','July','August','September','October','November','December'); $day = 1; $year = 2008; ?> <h2>Post a Journal Entry</h2> <div id="right"> <?php # If statement that detects if the form as been submitted. if (isset($_POST['submitted'])) { # Write out a thank you message if form was filled out correctly. If not, write out an error message. if (!empty($_POST['title']) && ($_POST['entry'])) { echo "<p class=\"green bold\" style=\"margin-bottom:10px;\">Thank you. Your entry has been posted.</p>"; } else { echo "<p class=\"red bold\">Your entry has the following errors!</p>"; # Write out an error message if title is empty. echo "<ul id=\"error_list\">"; if (!empty($_POST['title'])) { $title = $_POST['title']; } else { $title = NULL; echo "<li>You didn't enter a title!</li>"; } # Write out an error message if the content is empty. if (!empty($_POST['entry'])) { $title = $_POST['title']; } else { $title = NULL; echo "<li>You didn't make an entry!</li>"; } echo "</ul>"; include_once('journal_entry_form.php'); } } # Include the form include_once('journal_entry_form.php'); ?> </div> </div> <!-- include the footer //--> <?php include('includes/footer.php'); ?> </body> </html> The page can be seen here: http://www.matthewandchris.com/test.php Quote Link to comment Share on other sites More sharing options...
trq Posted October 13, 2008 Share Posted October 13, 2008 Change this... } # Include the form include_once('journal_entry_form.php'); to... } else { # Include the form include_once('journal_entry_form.php'); } Quote Link to comment Share on other sites More sharing options...
mattrd Posted October 13, 2008 Author Share Posted October 13, 2008 holy crap. DUH! So simple. Thank you so so much!! Quote Link to comment 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.