Solved

Redirecting in PHP

Posted on 2003-10-23
9
1,088 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

734 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