Note that there are some explanatory texts on larger screens.

plurals
  1. POajax validation for multiple forms on page, all have same class
    text
    copied!<p>basically i am making a CMS and want to have in post editing.</p> <p>How it works atm is that the blog post is echoed out (PHP) and there is a hidden ckeditor which when an edit button is clicked gets displayed. The edit button is then replaced with a save button.</p> <p>This all works fine and good however the issue comes when saving the blog post.</p> <p>the php works fine, and the ajax validation also works fine but ONLY when there is 1 blog post.</p> <p>When there is more than 1 post the errors come. The issue is that it seems to be that the save post button is sending all of the data from every blog post. I checked it with the firebug net and saw that all data is being sent.</p> <p>I just need a way of making it so that the save button in the form, only affects the data inside of that form. At the moment the error / success message is displayed by all of them.</p> <p>Here is the post echoed out:</p> <pre><code>&lt;div class="blogtest"&gt; &lt;form action="process/updatepost.php" class="updatepost" method="post"&gt; &lt;input type="button" class='.$editenabled.' value="Edit"&gt; &lt;input type="submit" class="saveupdatebutton" value="Save"&gt; &lt;input type="hidden" class="postid" name="postid" value="'.$postID.'"&gt; &lt;div class="text"&gt; &lt;div class="buildtext"&gt;'.$text.'&lt;/div&gt; &lt;div class="editor"&gt;&lt;textarea name="ckeditor" class="ckeditor"&gt;'.$text.'&lt;/textarea&gt;&lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>This is the javascript:</p> <p>$(document).ready(function(){ $(".updatepost").submit(function(){</p> <pre><code> $(".error").remove(); $(".success").remove(); // If there is anything wrong with // validation we set the check to false var check = true; // Get the value of the blog update post var blogpost = $('.ckeditor').val(); // Validation if (blogpost == '') { check = false; $('.ckeditor').after('&lt;div class="error"&gt;Text Is Required&lt;/div&gt;'); } // ... goes after Validation if (check == true) { $.ajax({ type: "POST", url: "process/updatepost.php", data: $(".updatepost").serialize(), dataType: "json", success: function(response){ if (response.databaseSuccess) $('.ckeditor').after('&lt;div class="success"&gt;Post Updated&lt;/div&gt;'); else $('.ckeditor').after('&lt;div class="error"&gt;Something went wrong!&lt;/div&gt;'); } }); } return false; }); </code></pre> <p>});</p> <p>Thanks for reading. Hope you can help.</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