0

I'm trying to add another parameter using a hidden input:

$('#form1').submit(function(){ //listen for submit event

        $('<input />').attr('type', 'hidden')
            .attr('name', 'id')
            .attr('value', id)
            .appendTo('#form1');

    return true;

});

"id" is a global variable.

My HTML form:

 <form id="form1" method=POST runat="server" enctype='multipart/form-data' action="/set_image">
       <div class="fileButtons">
       <input type='file' id="imgInp" name="imgInp" accept="image/*"/>
        <input type='button' id='remove' name="remove" value='Remove' />
        </div>
     <br>


<div class="modal-footer">
        <a type="button" class="btn pull-left" data-dismiss="modal">Cancel</a>
        <button type="submit" class="btn btn-primary pull-left">OK</button>
      </div>    
    </form>

In the log console of Google app engine, I can see that only "id" gets its value.

In firebug, it shows while debugging:

imgInp
    input#imgInp property value = "2.jpg" attribute value = "null"

main.py:

class SetImage(webapp2.RequestHandler):
    def post(self):
        id = str(self.request.get('id'))
        image = str(self.request.get('impInp'))
        ...

app = webapp2.WSGIApplication([ ('/set_image', SetImage),
                                ('/', MainPage)], debug=True)

I used the post in here:

https://stackoverflow.com/a/993897/2653179

Edit: The problem was solved, it was a typo in the imgInp variable in SetImage class...

Community
  • 1
  • 1
user2653179
  • 393
  • 1
  • 6
  • 21

3 Answers3

1
        $('<input />').attr('type', 'hidden')
        .attr('name', 'id')
        .attr('value', id)
thinker3
  • 12,771
  • 5
  • 30
  • 36
0

Add the new field this way:

$('#form1').submit(function(){ //listen for submit event

    $(this).append('<input name="' +id+ '" type="text" />');

});

jsFiddle

cssyphus
  • 37,875
  • 18
  • 96
  • 111
-1

There was a typo in getting the image in SetImage class... :)

I wrote impInp instead of imgInp...

user2653179
  • 393
  • 1
  • 6
  • 21
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – René Höhle Sep 12 '13 at 10:47
  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. – Michel Keijzers Sep 12 '13 at 11:13