Jump to content

Form display help


mattrd

Recommended Posts

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

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.