HTML Form HIdden Fields added with Javascript not POSTing

Posted by dscher on Stack Overflow See other posts from Stack Overflow or by dscher
Published on 2010-05-18T04:51:40Z Indexed on 2010/05/18 5:01 UTC
Read the original article Hit count: 281

Filed under:
|
|
|

I have a form where the user can enter a link, click the "add link" button, and that link is then(via jQuery) added to the form as a hidden field. The problem is it's not POSTing when I submit the form. It's really starting to confound me. The thing is that if I hardcode a hidden field into the form, it is posted, but my function isn't working for some reason. The hidden field DOES get added to my form as I can see with Firebug but it's just not being sent with the POST data.

Just to note, I'm using an array in Javascript to hold the elements until the form is submitted which also posts them visibly for the user to see what they've added. I'm using [] notation on the "name" field of the element because I want the links to feed into an array in PHP.

Here is the link creation which is being appended to my form:

        function make_hidden_element_tag(item_type, item_content, item_id)
{
    return '<input type="hidden" name="' + item_type + '[]" id="hidden_link_' + item_id + '" value="' + item_content + '"/>';

Does anyone have an idea why this might not be posting. As stated above, any hard-coded tags that are nearly identical to the above works fine, it's just that this tag isn't working. Here is how I'm adding the tag to the form with jQUery:

$('#link_td').append( make_hidden_element_tag('links', link, link_array.length - 1));

I'm using the Kohana 3 framework, although I'm not sure that has any bearing on this because it's not really doing anything from the time the HTML is added to the page and the submit button is pressed.

© Stack Overflow or respective owner

Related posts about html

Related posts about forms