?
Solved

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

Posted on 2012-08-10
6
Medium Priority
?
554 Views
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
0
Comment
Question by:egoselfaxis
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:soupBoy
ID: 38281530
How are you submitting your data?  Through ajax or through a 'standard POST' (if I can even say it that way.....lol).

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

Author Comment

by:egoselfaxis
ID: 38281548
I'm doing it via a standard POST... but using javascript:

document.getElementById('addNoteForm').submit();

Here is my form action tag:

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

- yg
0
 
LVL 8

Assisted Solution

by:soupBoy
soupBoy earned 400 total points
ID: 38281568
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...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Accepted Solution

by:
hielo earned 1600 total points
ID: 38281621

<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"

ex:
<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'].

Regards,
Hielo
0
 

Author Comment

by:egoselfaxis
ID: 38281651
>> 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
0
 
LVL 8

Expert Comment

by:soupBoy
ID: 38281672
Good find Hielo....awesome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

840 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