Solved

Redirecting in PHP

Posted on 2003-10-23
9
1,093 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

630 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