I tried using the example at http://www.w3schools.com/php/php_includes.asp

<a href="/default.php">Home</a>
<a href="/tutorials.php">Tutorials</a>
<a href="/references.php">References</a>
<a href="/examples.php">Examples</a>
<a href="/about.php">About Us</a>
<a href="/contact.php">Contact Us</a>
<html>
<body>

<div class="leftmenu">
<?php include("menu.php"); ?>
</div>

<h1>Welcome to my home page.</h1>
<p>Some text.</p>

</body>
</html>

I tried this:

<div id="topbar">
	<form method="post" action="parser.php">
		<p>URL: <input  type="text" name="url" size="80" /></p>
		<p><input type="submit" name="submit" value="View Feed" /></p>
	</form>
</div>
<div id="maincontent">
	<?php 
		if (isset($_POST['submit'])) {
			include 'parser.php';
		}
        ?>
</div>

And parser.php takes some input URL, parses it and outputs html but every time I click on submit, it takes me to another page instead of displaying the results in "maincontent". I can copy and paste the parser code and replace include 'parser.php' but is there a way to break it into separate files and make it work like the tutorial?

Basically I want the form to send values to another file and then have that file output the html back to the same form.

Thanks.

The form will be submitted to where the action parameter specifies.

eg:

<form method="post" action="parser.php">

will be submitted to parser.php

You can redirect to a different page using a HTTP redirect from that page after processing a form. Eg:

header("Location: /index.php");

will take you back to /index.php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.