Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <!-- Required meta tags -->
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
- </head>
- <body>
- <div class="container">
- <form method="POST" id="comment_form" onsubmit="return formSubmit();">
- <div class="form-group">
- <input type="text" name="comment_name" id="comment_name" class="form-control" placeholder="Name"></input>
- </div>
- <div class="form-group">
- <input type="text" name="comment_email" id="comment_email" class="form-control" placeholder="Email"></input>
- </div>
- <div class="form-group">
- <textarea name="comment_content" id="comment_content" class="form-control" rows="5" placeholder="Comment"></textarea>
- </div>
- <div class="form-group">
- <input type='hidden' name='comment_id' id='comment_id' value="0" />
- <input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit!"/>
- </div>
- <h3 id="comment_message"></h3>
- </form>
- <form method="POST" action="show_comments.php" id="display" onsubmit="return displayComments();">
- <div id="disp">
- </div>
- </form>
- </div>
- <script src="jquery-3.1.1.min.js" type="text/javascript"></script>
- <script src="popper.min.js" type="text/javascript"></script>
- <script src="bootstrap.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- /*
- * Duomenu rasymas i duomenu baze paspaudus submit.
- */
- function formSubmit(){
- $.ajax({
- type:'POST',
- url:'add_comment.php',
- data:$('#comment_form').serialize(),
- success:function(response)
- {
- $('#comment_message').html(response);
- displayComments();
- }
- });
- var form = document.getElementById('comment_form').reset();
- return false;
- }
- displayComments();
- /*
- * Duomenu atvaizdavimas
- */
- function displayComments()
- {
- $.ajax({
- type:'POST',
- url:'show_comments.php',
- data:$('#display').serialize(),
- dataType:'html',
- success:function(response)
- {
- $('#disp').html(response);
- }
- });
- return false;
- }
- </script>
- <script type="text/javascript">
- /*
- * Laukia kol bus paspaustas reply mygtukas
- */
- $(document).on('click','.reply',function(){
- var parentId= $(this).attr("id"); // id is duomenu bazes
- addChild(parentId);
- });
- /*
- * Komentaro-vaiko pridejimas
- */
- function addChild(parentId)
- {
- var chld='#child'+parentId; //sudaroma, kad rastu reikiama vieta
- $.ajax({
- type:'POST',
- url:'add_child.php',
- data:{parentId},
- dataType:'html',
- success:function(response)
- {
- $(chld).html(response);
- }
- });
- return false;
- }
- /*
- * laukia, kol paspaus submit
- */
- $(document).on('click','.submit_child',function(){
- var parentId= $(this).attr("id"); //
- addChildComment(parentId);
- });
- function addChildComment(parentId)
- {
- var name = document.getElementById('child_comment_name').value;
- var email= document.getElementById('child_comment_email').value;
- var content = document.getElementById('child_comment_content').value;
- $.ajax({
- type:'POST',
- url:'add_child_comment.php',
- data:{name,email,content,parentId},
- dataType:'html',
- success:function(response)
- {
- alert(response);
- displayComments();
- }
- });
- return false;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement