Posting data from a form that was dynamically generated using PHP and loaded via ajax

Posted on 2012-08-10
Last Modified: 2012-08-10
I've encountered a strange issue where data from a dynamically generated form isn't being POSTed.

I have some links labeled "Add Note" in my web app, and when they're clicked, an ajax function gets triggered which loads a dynamically generated (and JSON encoded/decoded) web form into a DIV directly underneath that link.

The form that's loaded & displayed is complete -- with both opening and closing form tags -- and consists of valid XHTML.  I've also made certain that the dynamically generated form isn't nested inside of another form.  But it appears that no matter what -- when that form gets submitted, ... none of the data actually gets POSTed, and I can't for the life of me figure out why.  

Does anyone here know why this is happening, and what I need to do to fix it?

Thanks in advance,
- Yvan
Question by:egoselfaxis
    LVL 8

    Expert Comment

    How are you submitting your data?  Through ajax or through a 'standard POST' (if I can even say it that

    You should post some code, especially the code that is firing the newly generated form to POST.

    Author Comment

    I'm doing it via a standard POST... but using javascript:


    Here is my form action tag:

    <form name="addNoteForm" id="addNoteForm" method="post" action="" enctype="multipart/form-data" />

    - yg
    LVL 8

    Assisted Solution

    In your function that is firing the submit(), are you able to see your data prior to submitting?

    Maybe you could 'alert' the data instead of submitting it to see if it is actually being sent.  This will let you know if the issue is on the frontend or the backend...
    LVL 82

    Accepted Solution


    <form name="addNoteForm" id="addNoteForm" method="post" action="" enctype="multipart/form-data" />
    If that is what you actually have, get rid of the slash before the ">".  Leaving it there closes the form prematurely.

    Another possibility, within the form in question, look for any element/tag with:
    name="submit" and/or id="submit" (lowercase "S")

    and change it to uppercase "S":
    name="Submit" and/or id="Submit"

    <input type="submit" name="submit" value="Submit">

    should be changed to:

    <input type="submit" name="Submit" value="Submit">

    NOTE: if the culprit is some form element, (<select>, <input>,<textarea>), then you may need to update your server-side script to look for $_POST['Submit']  instead of $_POST['submit'].


    Author Comment

    >> If that is what you actually have, get rid of the slash before the ">".  Leaving it there closes the form prematurely.

    A - ha!!!  That seemed to do the trick!  Thanks so much!!

    - yg
    LVL 8

    Expert Comment

    Good find Hielo....awesome.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now