I am developing a website where registered users can publish multiple articles. I have created a modal form with and input field for article heading and a text area for article stories, on submission, the form data goes into a contenteditable div which allows the user to edit all the published articles on server side. After editing, onblur the updated data get sent to a database using a form that gets populated with the updated data using a javascript code which takes the data from the content editable div to the form which then gets submitted to the database.
Now the problem is that only data from the first published article is getting sent to the database i have suspected that may be because all the published articles have the same id so I attached a form the script that stores the data on page so that each post have its own form but this has generated another problem where all the forms get submitted at the same time.
The three big question is how can I submit a form individually on a page with multiple forms? How can I update a post individually and send the updated data to a database from a page with multiple post? or is there a better way of doing this because my way is boring.
Please see my code below
<script>
function heading(){
document.getElementById('head').value = document.getElementById('title').innerHTML;
document.getElementById('stories').value = document.getElementById('story').innerHTML;
document.getElementById('authors').value = document.getElementById('author').innerHTML;
document.getElementById('biogid').value = document.getElementById('biogID').innerHTML;
}
</script>
<div id="article-container" title="Text editing is enabled on this page">
<?php if(empty($article)){ $article = "";}else{ foreach($article as $articles):?>
<?php echo "<div onclick=\"makeEditable(this)\" onblur=\"readOnly(this)\" id='article'>";?>
<?php echo "<h3 id='title'>" . $articles['heading'] . "</h3>";?>
<?php echo "<p id='story'>" . $articles['story'] . "</p>";?>
<?php echo "<p id='author' contentEditable=false>Author: " . $_SESSION['name'] . " " . $articles['time'] . "</p>";?>
<?php echo "<p id='biogID'>" . $articles['biogID'] . "</p>";?>
<?php echo "</div>";?>
<form action=
'?heading=<?php echo $articles['heading'];?>' method='post' onsubmit="heading();">
<input type='hidden' id='head' name='head' value=''>
<input type='hidden' id='stories' name='stories' value=''>
<input type='hidden' id='authors' name='authors' value=''>
<input type='hidden' id='biogid' name='biogid' value=''>
<input type='submit' name='update' value='Save changes'><br />
<?php endforeach;}?>
</div>