Solved

Redirecting in PHP

Posted on 2003-10-23
9
1,051 Views
Last Modified: 2008-02-01
Hi I did a registration form and I want that when the user have error when they submit the form that another window open with the errors over there and the main one with the registration form so they can modify theirs errors.

I now I can redirect with

header ("Location: test.php");

but I try to do the target in the location and I didn't make it work

Thanks

0
Comment
Question by:juanfigs
9 Comments
 
LVL 6

Expert Comment

by:aolXFT
ID: 9605547
You're going to have to give us way more information(and show us some code probably), before we can do anything to help.

How did it not work? What happened instead?

Did Location have any effect at all? Did you get any error messages(if so what were they)?

I understand you have a page, where they get a form, they fill it in. it is submitted to ANOTHER(different) page, The other page checks for errors, and should send it back to the first page if there are any, and if not continue on with it's jobs.

Is this understanding accurate?

PS, you will probably have to pass some params(or set cookies - params are better) to the script you are relocating them to, to pass on what errors they made.
0
 
LVL 9

Expert Comment

by:waygood
ID: 9606111
add in exit after your header(); as you dont want to process any more html or php after it.
and make sure you don't output anything prior to it either, like headers.

header("location: index.php");
exit;


e.g. Try this and use REFRESH and back and forward. You dont get the "resend form" message.

index.php
--------------------
<?php

if(sizeof($_POST)>0)
{
  // process post
  header("location: index.php?done=true");
  exit;
}
if($_GET="true")
{
   echo "done";
}
else
{
?>
<h3>my form</h3>
<form name="myform" method="post" action="index.php">
<input........
.....
</form>

<?php
}
?>
-----------------------
0
 
LVL 9

Expert Comment

by:waygood
ID: 9606165
I should read the questions better.

With mine you could validate and redo the form with the errors listed.

$error=array();
if(empty($_POST['cust_name']))
{
  $error['cust_name']="You must fill this in";

}
if( (sizeof($_POST)>0) && (sizeof($error)==0) )
{
  // process it with no errors
}
else
{
  // display form

.
.
<input name="cust_name" value="<?php echo $_POST['cust_name']; ?>" />
<?php echo $error['cust_name']; ?>
.
.

}
?>
0
 
LVL 5

Expert Comment

by:LornaJane
ID: 9606241
I think waygood's comment will be very helpful to you, and I would recommend that it would be more useful to return the form with the problems labelled than to open another window with this information in.  If you do want to open another window with this information in, you would be better off using javascript.  I can post an example if you still want to do it this way

Good luck!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:shmert
ID: 9607774
call ob_start() at the very beginning of your page, and then your call to header() will work.
0
 

Author Comment

by:juanfigs
ID: 9608180
Hi again.

The header ("Location: test.php")

that works but how about if i want to open that in a new small page not in the same one the user have the registration form.
0
 
LVL 6

Expert Comment

by:aolXFT
ID: 9610082
AFAIK if you want to open it in a new small page, you'll have to use JS.

If it was a hyperlink, you could use the target atribute, but I can't really see how to do wit with headers.
0
 
LVL 2

Accepted Solution

by:
ramonklown earned 100 total points
ID: 9614259
You have to do a post to a test page let's say testcode.php then if everything is okay (after all those ifs and stuff) you do a header to another page like

the code to post it to a new page in Javascript in full mode is

 <SCRIPT LANGUAGE="JavaScript">

function Start(page) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}
</SCRIPT>

THE BUTTON IS

<input type=button value="CLICK HERE" onclick="Start('testcode.php');">

<?
//testcode.php
if blah blah blah

else{

header ("Location: aproved.php")
}

?>

0
 
LVL 1

Expert Comment

by:pfiev
ID: 9620887
You should target your FORM in a new window, so
- if you've got errors, it will appear in your new windows
- if no error, your new windows should (that's your work) modify its opener (change its location) and close itself.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now