Note that there are some explanatory texts on larger screens.

plurals
  1. POform needs to be submitted twice before sending updated data
    primarykey
    data
    text
    <p>so basic outline...</p> <p>I have 'posts' pulled from the database and displayed like so:</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"id="ckeditor" class="ckeditor"&gt;'.$text.'&lt;/textarea&gt;&lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Once the edit button is clicked, the buildtext class hides and the ckeditor is shown. Same for the edit and save button.</p> <p>When save is clicked, a ajax call is made and then the data is updated. This works perfectly fine... however it only works perfectly fine if there is only 1 blog post on that page.</p> <p>Here is the ajax for reference:</p> <pre><code>$(document).ready(function(){ $(".updatepost").submit(function(){ var $targetForm = $(this); $targetForm.find(".error").remove(); $targetForm.find(".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 $ckEditor = $targetForm.find('.ckeditor'), 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: $targetForm.serialize(), dataType: "json", success: function(response){ if (response.databaseSuccess) $targetForm.find(".error").remove(); else $ckEditor.after('&lt;div class="error"&gt;Something went wrong!&lt;/div&gt;'); } }); } return false; }); </code></pre> <p>});</p> <p>So, if there is 2 blog posts on the page and i edit the 2nd (last) post, on clicking save the post is updated correctly.</p> <p>However if i edit any other then it takes two submits for the data to be sent.</p> <p>I checked on firebug and it shows that on the first click, the old value is sent, and then on the 2nd the new one.</p> <p>Where am i going wrong?</p> <p>Eventually (once working) the post will be refreshed on the success of the ajax call but for now its obviously vital that the user only has to click save once.</p> <p>Thanks for any help! Any more code needed and ill post it here.</p> <p>Craig :)</p> <p>EDIT: After making ckeditor just a normal textarea it works fine. Must be ckeditor not updating as i know it doesnt litrally work as a textarea as such. Maybe ill have to use another rich editor...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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