Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  permalink
    Hi,

    I'd like to make the following happen on a form in my site:
    User clicks on the "Submit" button, a file is force downloaded and then the form is submitted.
    Is this possible on a single button and a single onclick()?

    Mariachi Mike
    •  
      CommentAuthorkari.patila
    • CommentTimeNov 24th 2008 edited
     permalink
    It is, like this:

    <?php
    if($_POST){
    $filename = 'card.vcf';
    Header("Content-Disposition: attachment; filename=$filename");
    Header("Connection: close");
    Header("Content-Type: text/x-vCard; name=$filename");
    // continue to process the form
    }
    ?>


    If you wanted to be able to somehow initiate the download first and submit the form after that, I'm unable to help you.
  2.  permalink
    Unfortunately, that's what I wanted - to be able to initiate the download first and then submit the form.
  3.  permalink
    If there's a Javascript method of forcefully initiating a download, I haven't seen one. On the other hand though, it has never occurred to me to go about finding one. It might be possible to do an ajax call to a php script to start the download, and then use the return value as a trigger for submitting the form.

    Could you be more specific about the desired workflow?
  4.  permalink
    What I tried is like this:

    The onclick on the Submit button, set location.href = file to be downloaded, then return true to the submit.

    The resulting behavior is that the form submits, but no download.

    Looking at this ... it does seem that you'd have do use Javascript to force the download and return the result to the submit button. I wonder about the feasibility of this.
Add your comments
    Username Password
  • Format comments as (Help)