After DOM manipulation, form fields won't post...
This is an issue I first ran into several years ago, but I've recently helped two different people who had the same problem and thought it was worthy of blogging.
If you run into a situation where form fields are not getting posted to the server after the DOM has been manipulated, check to make sure the <form/> element is in a valid location. If the <form/> tag resides as a direct child of either a <table/> or <tr/> element, then you will encounter problems posting the form once a child element of the <form/> element has been dynamically modified.
While this behavior does not occur in IE, it does happen in other modern browsers—such as Firefox and some WebKit-based browsers.
Any of the following will break your form post submission:
<table><form><tr> .... </tr></form></table>
<table><tr><form> .... </form></tr></table>
<table><tbody><form> ... </form></tbody></table>
To correct the problem, just place the <form/> tag outside of the <table/> tag:
<form><table><tr> ... </tr></table></form>
This type of markup usually appears on older sites, where I believe the intent of putting the <form/> tag inside the <table/> was to prevent any visual margins from being seen. Obviously, it's easy to remove the margins using CSS and this type of invalid markup can only come back to haunt you.
NOTE: You can do <table><tr><td><form> .... </form></td></tr></table>. That's perfectly valid HTML. You just need to make sure the <form/> tag is placed somewhere were visible text is allowed.
Comments
Glad this post helped. Thank goodness Google works fast! It's weird that I've run into several people lately who've run into this problem. I suspect it's just that more an more developers are trying to add functionality to old legacy pages.
...
keywordsUnpaid[0].keywordUnpaid fish
keywordsUnpaid[1].keywordUnpaid bird
...
Fish was the initial value of the indexed fields, and bird has been added.
I get
Message: BeanUtils.populate
javax.servlet.ServletException: BeanUtils.populate
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
As long as I don't add fields everything works just fine. I can work around it by just putting the new values comma separated in a hidden field, but it'd be nice to get it working as initially intended. Well, anyway ... that's for tomorrow ...
Regards to Nikki and Maddie, I have a 14 year old labrador - Bamse - and he's still going strong ... :-)
It wouldn't suprise me if you had the tags in an invalid order, like
[div]
[form]
[/div]
[/form]
I've seen that cause problems to. The markup should be in a valid order:
[div]
[form]
[/form]
[/div]
That might not have been the case, but it wouldn't surprise me if it was the root problem.
