Page 1 of 1

Header and Form Action issue

Posted: Tue Jun 02, 2009 5:43 pm
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?

Re: Header and Form Action issue

Posted: Thu Jun 04, 2009 4:30 pm
by sirstrumalot
Anyone?

Re: Header and Form Action issue

Posted: Thu Jun 04, 2009 5:30 pm
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.