Solved

Redirecting in PHP

Posted on 2003-10-23
9
1,062 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

920 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

14 Experts available now in Live!

Get 1:1 Help Now