Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headers & exit() causing an unresponsive form submit

Tags:

html

php

Problem After downloading a CSV once, the form does not send a request on submission.

Purpose: To download a CSV file of information after choosing a few criteria for the download.

PHP Scripts:

export.php displays a HTML Form allowing the user to select certain criteria (which basically sets a couple of variables and then submitting those criteria in order to download the CSV file.

exportEntrants.php uses those variables set by the form to retrieve the appropriate data from the database, create the CSV data and then provide it as a download to the user.

So in export.php we have the following snippet:

require_once 'exportEntrants.php';
if(/*the form is submitted*/){
    export($criteria);
}
else{
    // Display the HTML Form
}

Which successfully calls the exportEntrants.php script when the form is submitted the first time.

Then in exportEntrants.php the data is created correctly and downloaded using:

function download($content,$title) {
        header('Content-Description: File Transfer');
        header("Content-type: application/csv");
        header('Content-Disposition: attachment; filename="'.$title.'.csv";');
        echo $content;
        exit();
    }

After which, the download works fine, and the CSV is correct. However on-screen the form is still visible to the user, so clicking the Submit button once more should trigger the if statement described above and allow me to download the file again with the same or different criteria as I see fit.

This doesn't happen though, nothing happens. The form is still displayed on screen, nothing has changed on screen at all, but submitting the form does not reload the page or cause any action.

Can anyone see what could be causing this problem? I will provide any additional information as needed.

Thank you.

EDIT in response to Comment from Hakre below.

  • Disabling Javascript made no difference.

  • This issue has been tested in Firefox 7.0.1 and Chrome 14. I have not yet tried IE or Safari.

  • The HTML of the form is as follows (I haven't included the criteria parts of the form as they work fine and the form is generated by a rather complicated function so it's not a small piece of HTML (lots of divs and spans):

    <form action="/admin/export/export.php" method="post" name="exportForm" onsubmit="return formSubmit()"><input type="submit" name="submit_butt" value="EXPORT" class="button"></form>

like image 695
Houdmont Avatar asked Nov 14 '22 15:11

Houdmont


1 Answers

The fact that the request is not being sent, when you press button repeatedly, seems to indicate an issue in client side. Check the formSubmit() function or page source of the client-side and see if maybe the attachment download somehow messed up Javascript.

like image 85
Gnudiff Avatar answered Dec 18 '22 20:12

Gnudiff