Jump to content

how to send html form data to php file


doforumda

Recommended Posts

hi

 

i have html form in which i want to send its data to php file using ajax but the problem i think is in php file because when i use firebug then it displays error in php file which says "Undefined index:  comment in php file" here is my code

 

php file

<?php
$comment = strip_tags($_POST['comment']);
//$postId = strip_tags($_POST['postId']);
$commentDate = date("Y-m-d");
$commentTime = date("h:i:s A");

echo $comment;
?>

 

html file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
<script src="js/script.js" type="text/javascript"></script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <textarea name="textarea" id="comment" cols="45" rows="5"></textarea>
    </label>
  </p>
  <p>
    <label>
      <input type="button" name="button" id="button" value="Submit" onclick="postcomment()" />
    </label>
  </p>
</form>
</body>
</html>

 

and js file

function postcomment() {
      var url = 'comments.php';
      //var queryString = $("#commentForm").serialize();
      var comment = $('#comment').val();
       //var postId = $('input#postId').val();
      
      var queryString = 'comment=' + comment;// + '&postId=' + postId;
      alert(queryString);
      $.ajax ({
         type: 'POST',
         url: url,
         data: 'html',
         dataType: queryString,
         success: displayComments
      });
      
      function displayComments(resultData) {
         $('#displayComments').html(resultData);
      }
}

Link to comment
https://forums.phpfreaks.com/topic/192021-how-to-send-html-form-data-to-php-file/
Share on other sites

I think I see it

 

$.ajax ({

        type: 'POST',

        url: url,

        data: 'html',

        dataType: queryString,

        success: displayComments

      });

 

should be

 

$.ajax ({

        type: 'POST',

        url: url,

        data: queryString,

        dataType: 'html',

        success: displayComments

      });

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.