Sang Froid
Sang Froid

Reputation: 983

PHP form stays at form action

I have an HTML form with a form action of foo.php. However, when I click the submit button, I get redirected to the "foo.php", but I don't get redirected back to the page where the form is located. Could anyone tell me if there is some sort of code that is necessary for this to happen?

Here's my PHP file, if this helps:

<?php

$title = $_POST['title'];
$content = $_POST['content'];
$postid = $_POST['postid'];

?>

Upvotes: 0

Views: 104

Answers (3)

Nazmul Hasan
Nazmul Hasan

Reputation: 7040

It very simple. Try to understand your task first. You need to redirect to another page after completing your task whatever save/update/processing data.

just set header in your php script after completing your work.

<?php


 // your all code will goes here
 header("Location: myform.php");  

?>

Upvotes: 0

Gaurav
Gaurav

Reputation: 628

Two ways:

<?php
header('Location: myform.php');
 ?>

or use javascript:

<script>
window.location('myform.php');

Upvotes: 1

Shakti Singh
Shakti Singh

Reputation: 86336

You can set header redirect back to form file, after processing the form data. Assuming your form file has name "form.php"

header('location: form.php');

Upvotes: 1

Related Questions