Note that there are some explanatory texts on larger screens.

plurals
  1. POajax js serialize not reading form elements
    text
    copied!<p>Have a form that is not being read by serialize() function. </p> <p><br><br></p> <pre><code> &lt;script type="text/javascript"&gt; function submitTrans1(){ var formData = $('form1').serialize(); var options = { method:'post', postBody:'formData', onCreate: function(){alert(formData)}, onSuccess: function(transport){alert("onSuccess alert \n" + transport.responseText);}, onComplete: function(){alert('complete');}, onFailure: function(){alert('Something went wrong...')} } new Ajax.Request('/clients/addTrans/&lt;?=$clientID123?&gt;/',options); } &lt;/script&gt; &lt;?php $datestring = "%Y-%m-%d"; $time = time(); $clid1 = $this-&gt;uri-&gt;segment(3); ?&gt; &lt;form name="form1" id="form1"&gt; &lt;div id="addTransDiv" style="display:none"&gt; &lt;div class=""&gt; &lt;label for="transDesc" id="transDesc" value="sadf" class="preField"&gt;Description&lt;/label&gt; &lt;textarea cols="40" rows="3" id="transDesc" value="" name="transDesc" class=""&gt;&lt;/textarea&gt; &lt;/div&gt; &lt;div class=""&gt; &lt;label for="date" class="preField"&gt;Date&lt;/label&gt; &lt;input type="date" id="transDate" name="date" value="&lt;?=mdate($datestring, $time);?&gt;" size="40" class=""/&gt;&lt;br/&gt; &lt;/div&gt; &lt;div class=""&gt; &lt;label for="userfile" class="preField"&gt;File&lt;/label&gt; &lt;input type="file" name="transFile" id="userfile" size="20" /&gt;&lt;br&gt; &lt;/div&gt; &lt;input type="button" id="submitTrans" name="submitTrans" value="Submit" onclick="submitTrans1()"&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>Uh, I have an alert in the onSuccess parameter of the Ajax.Request that would ideally alert the variable assigned to the serialized form. However, when it alerts, it alerts nothing. I also have the processing url printing out the $_POST data just in case, but that as well returns an empty array in the responseText, so indeedidly nothing is being posted to the form.</p> <h2>Thx.</h2> <p>Edit1</p> <p>it seems that the problem might be related to the fact that the form is inside a div. If I remove everything on the page except for the form and js, it works ok. But the form is in a div that is hidden by default and uses another function to be displayed. Is there some kind of magic needed to get form data via serialize if it's in a div?</p> <hr> <p>Edit 2</p> <p>Tried adding quotes and pound signs and all that other jazz. I am using web developer toolbar, firebug, etc... it isn't throwing any js errors and doesn't afraid of anything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload