11

Relating to my last question. I have an upload field where the user can choose a picture and this becomes resized (client-side via JavaScript), base64 encoded (JavaScript as well) and sent via a hidden field. I do this in order to save bandwidth of the user (e.g. usage with a 3G connection).

But I don't know how to not send the user upload file <input type="file" name="file" id="file" class="span4"> within the <form> tags. The obvious solution would be to exclude the file upload field from the form but this would kill my layout. Is this possible?

Community
  • 1
  • 1
Kurt
  • 311
  • 1
  • 3
  • 9

4 Answers4

22

Just delete name="file" attribute.

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
VALIKHAN
  • 391
  • 3
  • 3
14

You can do the following with jQuery to disable your input field:

$('#file').prop('disabled', true);

Altogether you might have this:

// domReady handler
$(function() {

    // provide an event for when the form is submitted
    $('#myform').submit(function() {

        // Find the input with id "file" in the context of
        // the form (hence the second "this" parameter) and
        // set it to be disabled
        $('#file', this).prop('disabled', true);

        // return true to allow the form to submit
        return true;
    });
});
Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
3

If you can add the attribute "disabled" to the input, it won't be submitted along with the form:

<input type="file" name="file" id="file" class="span4" disabled="disabled">

You can set this attribute in your js-script...

darwin
  • 211
  • 3
  • 15
0

I needed the form and the input to have a name tag so what i have to do was to set a method tag on my form. This way, my inputs can be enabled and have a tag name.

<form name="form" method="post">
Alysson Myller
  • 1,203
  • 11
  • 13