Header and Form Action issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Header and Form Action issue

Post by sirstrumalot »

Okay, this shouldn't be too hard...

Here in this example I am writing comma seperated $_POST values from the form to a .csv file created based on the record name:

Code: Select all

 
$csv_output = '"Appointment Time","Appointment Time 2","Appointment Date","Therapy Type","Comments"';
$csv_output .= "\n"; 
$csv_output .= '"'.$_POST['missed_aptTime'].'","'.$_POST['missed_aptTimeAMPM'].'","'.$_POST['missed_aptDate'].'","'.$_POST['missed_therapyType'].'","'.$_POST['missed_comments'].'"';
$csv_output .= "\n"; 
 
$name = '"'.$_POST['contact_first'].''.$_POST['contact_middle'].''.$_POST['contact_last'].''.date('mdY-Hi').'"';
 
f(isset($_POST['Submit'])){
 
  //You cannot have the breaks in the same feed as the content. 
  header("Content-type: application/vnd.ms-excel");
  header("Content-disposition: csv; filename=$name.csv");
    print $csv_output;
        exit;
}
The problem I have is that I can't figure out how to use the header to 1) Render the csv file with the data and 2) redirect to the next page. How can I redirect the page once the download box pops up? If I try to add the header redirect below, it says the header has already been assigned. I tried the

Code: Select all

<form action="redirect_page.php">
but it overrides the csv creation in the header. Any way to do one and then the other?
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Re: Header and Form Action issue

Post by sirstrumalot »

Anyone?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Header and Form Action issue

Post by Darhazer »

You cannot send data and redirect user at once.
In order to do that, you have to load the script, that sends the CSV file, in a iframe, and when it finish, you have to redirect using JavaScript.
Post Reply