Html code for adding comments by users. Simple commenting system using AJAX. Which markup format is best to use

💖 Like it? Share the link with your friends

According to a study by C5Insight, a CRM implementation company, an average of 38% of CRM integrations into businesses fail to deliver results that are predicted. The reason is not in a bad IT product, but in the fact that companies do not know how to properly implement CRM, make mistakes and eventually lose their investments.

But if the transition to CRM is successful, then the investment will pay off more than 5 times. According to a study by the analytical company Nucleus Research, every dollar invested in CRM brings 5.6 dollars in profit.

Return on investment in a CRM product for business according to the analytical company Nucleus Research in 2011

To understand how the implementation of an IT product should take place, we will consider the main stages of integration, as well as typical mistakes that entrepreneurs often make.

Implementation stages

The implementation of CRM takes place in different ways, but there are always five main stages in this process. On each of them, an integrator acts as a curator - a representative of a CRM company, but do not worry: you do not have to write a "test". You just need to follow the instructions of the integrator: accurately describe the business processes and problems that you want

1. Description of business processes

Since the CRM system allows you to improve and automate existing processes, first you need to describe them. These data will form the basis of the program settings:

  • What is the structure of the company? How are people divided among departments? How are tasks distributed among employees?
  • Who are the company's clients? , How ?
  • What is the algorithm of interaction with clients?
  • How is customer loyalty handled? How does marketing work in general?
  • Which ones are used in the company?

2. Drawing up terms of reference

When business processes are described, weaknesses need to be analyzed. After all, it is precisely for their elimination that the program is being implemented.

For example, your managers are slow to respond to new requests from the company's website - call back customers only the next day or even forget about them. As a result, the company loses potential customers. This must be specified in the terms of reference for the integrator to offer a solution to the problem. But this will happen in the next step.

3. Formation of a map of settings

Business processes are described, problems are identified, and now we need to figure out how to “defeat” them with the help of the system: what processes can be optimized, accelerated, automated. For example, you can automate invoicing, and so on.

At this stage, the leading role is assigned to a CRM specialist. He thoroughly knows the capabilities of an IT product and can offer such nuances that the consumer did not even know existed. In addition, the integrator can advise or improve interaction with customers - that is, he also acts as a consultant.

If we continue the example from the previous stage, then the integrator can offer such a way to deal with lost customers: set up CRM integration with the site so that each request is automatically recorded in the program and a responsible manager is appointed for it. The system will automatically set him the task of calling the client within 15 minutes, and if the task is overdue, the head of the sales department will instantly know about it through a programmatic notification.

4. CRM setup, import, integration

This stage is a technical implementation of the previous one. The work falls entirely on the implementation specialist. It imports data, sets up a sales funnel and checklists, creates custom fields, writes scripts for automating business processes - in a word, adjusts the system interface to suit your business. In addition, at this step, CRM integration with third-party services that you use in your work is configured: mail, company website, sms mailing service, and others.

5. Personnel training

It makes no sense to figure out how to implement CRM in a company if employees cannot work with it competently. CRM is only a tool that does not bring profit in itself, so it is important to explain to employees what this incomprehensible program is, and why it is so important to painstakingly record customer and transaction data in it at every stage of work.

For example, he called the client - wrote down the result of negotiations in his card; did not get through - set a reminder to call back in 2 hours; closed the deal - noted in CRM that the sale is completed, and then the client will automatically receive an SMS with a request to give a review.

If this is not done, then sales reports will be incorrect, will not work, and the database will turn into a mere collection of names and phone numbers.

In fact, many find it difficult to formulate problems, identify weaknesses in work affairs and understand which business processes need to be automated. To do this, it is better to immediately contact the developer and ask for help.

Why didn't it work? We analyze implementation errors

Even if you have chosen the right system and understand how to correctly implement CRM, you are still not immune from. Fortunately, you can use the experience of other companies to improve your chances of success.

1. Haste in the initial stages of implementation

Most often, mistakes are made in the early stages of system implementation. Shortcomings in the description of business processes and "bottlenecks" in the sales funnel can lead to the fact that the CRM system does not integrate into the real activities of the company, and even more so does not help in solving problems.

Stop rushing and carefully follow the recommendations of a CRM specialist. If you have a small company of 10-20 people, the integration will take 2-3 weeks. If we are talking about a large corporation, then a smooth process can take up to six months. Before you implement a CRM system, be sure to focus on these deadlines.

2. Insufficient integration options

It is important that the CRM system is well integrated with other software that the company uses. Otherwise, you will never achieve that the program has all the relevant sales information and that it works without failures.

According to C5Insight, the more different programs used in the company, the worse the implementation results. The fact is that information in different services is not synchronized, and you have to manually duplicate the same information in several programs, for example, in CRM and in 1C Accounting. As a result, a lot of time is wasted, errors appear in the data, and the reports stop “telling” the truth.

Even at the system selection stage, make a list of software and services with which integration is needed, and provide it to the implementation specialist. At the same time, you need to delegate processes from other software products to CRM. For example, abandon Outlook and use

According to C5Insight, 35% of CRM users cite software integration as a key difficulty when moving to a CRM solution. And if the system you choose does not support the necessary integrations in principle, then this difficulty will become fatal.

3. Poor employee training

A CRM system is a technology, it can help the team, but it does not take over its work. Employees must understand, otherwise the "exhaust" will be minimal. Arrange an introductory presentation, record video lessons with detailed instructions, conduct a mini-exam, personally train the heads of departments so that they transfer knowledge to subordinates through the hierarchy. Let employees understand what depends on them, how your investments will recoup.

Instead of a conclusion

There is a well-known principle: 40% of the effect of integration is achieved through competent planning, 20% through the use of the right technologies and 40% through . Therefore, in order to avoid mistakes when implementing an IT product, act “with feeling, with sense, with arrangement”, and the result will not be long in coming.

Want to know more? Ready to start implementing a CRM system? V convenient program right now, our specialists will call you back and advise you on all your questions.

Step 1 - XHTML

First, let's look at the comment markup. This code is generated by PHP with the class Comment .

demo.php

Username
Jun 30, 2010

Comment text

div avatar contains a link (if the user entered the correct URL when posting the comment) and the avatar image we get from gravatar.com . We'll return to generating the markup in the PHP step. At the end follow div name div time and comment text.

Another important element in XHTML is the comment form. She sends with POST. All fields except URL must be completed.

demo.php

Add a comment

The form is sent from using AJAX. The check is performed in background V submit.php. Each field has a corresponding element label, with attribute set for .

Step 2 - PHP

PHP handles communication with the database MySQL data and generates the markup for the comment. It also gets the end of the AJAX request and inserts the comment data into the table comments.

demo.php

/* / Select all comments and populate the $comments array with objects */ $comments = array(); $result = mysql_query("SELECT * FROM comments ORDER BY id ASC"); while($row = mysql_fetch_assoc($result)) ( $comments = new Comment($row); )

MySQL query select all records from table and populate array $comments class objects comment. This array is output further when the script is executed.

demo.php

/* / Print comments one by one: */ foreach($comments as $c)( echo $c->markup(); )

Each comment has a method markup(), which generates correct HTML code ready to be displayed on the page. Following are the class and method definitions.

The class receives a row from the database (obtained using mysql_fetch_assoc()) and store it in a variable $data. It is available only to the class method.

comment.class.php - Part 1

class Comment ( private $data = array(); public function __construct($row) ( /* / Constructor */ $this->data = $row; ) public function markup() ( /* / This method outputs the XHTML markup for the comment */ // Set an alias so you don't have to write it every time $this->data: $d = &$this->data; $link_open = ""; $link_close = ""; if($d["url"])( // If a URL was entered when adding a comment, // determine the opening and closing link tags $link_open = ""; $link_close = ""; ) // Convert the time to UNIX format: $d["dt"] = strtotime($d["dt"]); // Needed to set the default image: $url = "http://".dirname($_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"])."/img/default_avatar.gif"; return"
".$link_open." ".$link_close."
".$link_open.$d["name"].$link_close."
".date("d M Y",$d["dt"])."

".$d["body"]."

"; }

The script uses gravatar to represent the avatar in the comments. Gravatar is a very useful service that matches an avatar with an email address. The avatar image can be easily obtained by passing the encoded function md5() your email address on gravatar.com.

The script determines the URL on which it is executed and determines the exact address of the image default_avatar.gif. This image is passed along with the md5 hash, and if no avatar was found for the given email address, then an alternative image will be displayed.

comment.class.php - Part 2

public static function validate(&$arr) ( /* / This method is used to validate data sent via AJAX. / / It returns true/false depending on the validity of the data, and fills / the $arr array, which is passed as a parameter with either data or */ $errors = array(); $data = array(); // Use the filter_input function introduced in PHP 5.2.0 if(!($data["email"] = filter_input(INPUT_POST,"email ",FILTER_VALIDATE_EMAIL))) ( $errors["email"] = "Please enter a valid Email."; ) if(!($data["url"] = filter_input(INPUT_POST,"url",FILTER_VALIDATE_URL))) ( // If an invalid URL was entered in the URL field, // act as if no URL was entered: $url = ""; ) // Use a filter with a callback function: if(!($data["body"] = filter_input(INPUT_POST,"body",FILTER_CALLBACK,array("options"=>"Comment::validate_text")))) ( $errors["body"] = "Please enter comment text."; ) if(!( $data["name"] = filter_input(INPUT_POST,"name",FILTER_CALLBACK,array("options"=>"Comment::validate_text")))) ( $errors["name"] = "Please enter a name. "; ) if(!empty($errors))( // If there are errors, copy the $errors array to $arr: $arr = $errors; return false; ) // If the input is correct, clean up the data and copy it to $arr : foreach($data as $k=>$v)( $arr[$k] = mysql_real_escape_string($v); ) // email must be lowercase: $arr["email"] = strtolower(trim($ arr["email"])); return true; )

Method validate()(also part of a class) is defined as static. This means that it can be called directly with the construct comment::validate(), without creating a class object. This method validates data that is passed through AJAX.

The method uses new feature filter, which became available in PHP 5.2.0. This way we can easily check and filter the data that is passed to the script. For example, filter_input(INPUT_POST,'url',FILTER_VALIDATE_URL) means we check if $_POST["url"] correct URL. If so, then the function returns the value of the variable, otherwise it returns the value false.

Before using such a function, one had to use regular expressions for data validation (using a series of constructs if). An added advantage is that we get the data before doing any specific transformations.

It is also possible to define a function that will perform additional data modifications.

comment.class.php - Part 3

private static function validate_text($str) ( /* / This method is used as FILTER_CALLBACK */ if(mb_strlen($str,"utf8")<1) return false; // Кодируем все Special symbols html (<, >, ", & .. etc) and convert // the newline character to a tag
: $str = nl2br(htmlspecialchars($str)); // Remove any remaining newlines $str = str_replace(array(chr(10),chr(13)),"",$str); return $str; )

Last Method validate_text passed as a return function in two calls filter_input. It converts all special HTML characters, which effectively blocks XSS attacks. Also it replaces newlines with tags
.

submit.php

/* / This array will be filled with either data / that are passed to the script, / or error messages. /*/ $arr = array(); $validates = Comment::validate($arr); if($validates) ( /* All right, insert data into the database: */ mysql_query(" INSERT INTO comments(name,url,email,body) VALUES ("".$arr["name"]."", "".$arr["url"]."", "".$arr["email"]."", "".$arr["body"]."")"); $arr["dt "] = date("r",time()); $arr["id"] = mysql_insert_id(); /* / The data in $arr is prepared for mysql query, / but we need to display it, so / we are preparing all elements in the array: /*/ $arr = array_map("stripslashes",$arr); $insertedComment = new Comment($arr); /* Print the markup of the comment just inserted: */ echo json_encode(array("status "=>1,"html"=>$insertedComment->markup())); ) else ( /* Display error messages */ echo "("status":0,"errors":".json_encode($arr ).")"; )

submit.php fetches a comment from the data via an AJAX request. Validates it and outputs a JSON object containing either XHTML markup with an embedded comment or a list of errors. jQuery use property status to determine what should be displayed - either an error message or adding comment markup to the page.

Below are two examples.

Successful response

( "status": 1, "html": "Html Code Of The Comment Comes Here..." )

Property html contains the comment code.

Error response

( "status": 0, "errors": ( "email": "Please enter a valid Email.", "body": "Please enter a comment body.", "name": "Please enter a name." ) )

When there is an error, jQuery loops through the errors object and displays messages next to the fields that have errors.

Step 3 - CSS

Now that the markup is correctly generated and displayed on the page, we can move on to styling.

styles.css - Part 1

.comment, #addCommentContainer( /* Style for comments */ padding:12px; width:400px; position:relative; background-color:#fcfcfc; border:1px solid white; color:#888; margin-bottom:25px; / * CSS3 rounded corners and shadows */ -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; -moz-box-shadow:2px 2px 0 #c2c2c2; -webkit-box- shadow:2px 2px 0 #c2c2c2; box-shadow:2px 2px 0 #c2c2c2; ) .comment .avatar( /* / The avatar is positioned absolutely. / Outer offset for the comment div /*/ height:50px; left:-70px; position :absolute; width:50px; background:url("img/default_avatar.gif") no-repeat #fcfcfc; /* Center vertically: */ margin-top:-25px; top:50%; -moz-box-shadow :1px 1px 0 #c2c2c2; -webkit-box-shadow:1px 1px 0 #c2c2c2; box-shadow:1px 1px 0 #c2c2c2; )

div .comment And #addCommentContainer have the same style. Several CSS3 rules are used to round corners and reflect shadows.

styles.css - Part 2

.comment .avatar img( display:block; ) .comment .name( font-size:20px; padding-bottom:10px; color:#ccc; ) .comment .date( font-size:10px; padding:6px 0; position:absolute; right:15px; top:10px; color:#bbb; ) .comment p, #addCommentContainer p( font-size:18px; line-height:1.5; overflow-x:hidden; ) #addCommentContainer input, # addCommentContainer textarea( /* Input style */ display:block; border:1px solid #ccc; margin:5px 0 5px; padding:3px; font-size:12px; color:#555; font-family:Arial, Helvetica, sans-serif; ) #addCommentContainer textarea( width:300px; ) label( font-size:10px; ) label span.error( color:red; position:relative; right:-10px; ) #submit( /* "Submit" button " */ background-color:#58B9EB; border:1px solid #40A2D4; color:#FFFFFF; cursor:pointer; font-family:"Myriad Pro",Arial,Helvetica,sans-serif; font-size:14px; font -weight:bold; padding:4px; margin-top:5px; -moz-border-radius:4px; -webkit-border-radius:4px; border-radius:4px; ) #submit:hover( background-color:# 80cdf5; border-color:#52b1e2; )

In the second part, we set the styles for comments and form elements. Let's note the selector input, which highlights elements depending on an attribute type.

Step 4 - jQuery

Now let's move on to jQuery.

script.js

$(document).ready(function()( /* The following code is executed only after the DOM is loaded */ /* This flag prevents multiple comments from being submitted: */ var working = false; /* Catching the form submit event: */ $(" #addCommentForm").submit(function(e)( e.preventDefault(); if(working) return false; working = true; $("#submit").val("Working.."); $("span .error").remove(); /* Submit form fields to submit.php: */ $.post("submit.php",$(this).serialize(),function(msg)( working = false; $ ("#submit").val("Submit"); if(msg.status)( /* / If the insert was successful, add a comment / below the last one on the page with a slideDown effect /*/ $(msg.html).hide ().insertBefore("#addCommentContainer").slideDown(); $("#body").val(""); ) else ( /* / If there are errors, loop through the object / msg.errors and output them to page /*/ $.each(msg.errors,function(k,v)( $("label").append(" "+v+""); )); ) ),"json"); )); ));

We use a function call $(document).ready() A that binds a function to the event . Variable working acts as a flag that signals that an AJAX request is in progress (thus preventing duplication of the same comment).

In the return function for the POST AJAX request, we check the property status to determine if the comment was inserted successfully. If yes, we add the resulting markup to the page after the last comment with animation slideDown.

If there were problems, then we display error messages by adding span error to the corresponding element label(element attribute label contains id input that has an error).

Ready!

Conclusion

To run the script on your server you need to create a table comments in your MySQL database. You can do it with SQL code from file table.sql, which must be entered on the SQL tab in phpMyAdmin. Then you need to set the MySQL database connection parameters in the file connect.php .

Now it has become fashionable to replace the usual WordPress comment system with comments from one of the most popular social networks Facebook. We have previously published, but a lot of time has passed since then, and now this procedure has been noticeably simplified thanks to the ready-made WordPress plugin. So this time it will be much easier.

We will tell you how to implement Facebook comments on your site a little later, but first we will try to determine the pros and cons of such a replacement.

Comments from Facebook: pros and cons

In addition, the factor of the so-called anonymity. It is unlikely that spam comments will be added from Facebook, since all of them are tied to real user accounts.

However, there are also disadvantages to such a system. Many users prefer anonymity and not at all because they want to write something bad or leave spam. No. It is purely a matter of the psychological moment and the feeling of discomfort and embarrassment that they experience when speaking out in public. This factor can reduce user activity.

Unlike other comment systems like Disqus, Facebook comments do not sync with native WordPress comments. They completely replace them. If old posts already have WordPress comments, they will appear before or after new comments added via the Facebook form.

Here, perhaps, are all the pros and cons of Facebook comments.

If you haven't yet changed your mind about installing them on your WordPress site, then read below on how to do so.

Facebook Comments plugin for WordPress

First, install and activate the plugin Facebook Comments and configure it in the menu that appears under Settings → Facebook Comments.


To start using comments on the site, you first need to create a Facebook application.

If you have previously created an application, you can use its ID data right now. Otherwise you will have to create a new one on the page Facebook Apps:

The control panel of the newly created application will display its ID, which you need to copy and paste into the plugin settings. But before that, set up the application on your site in "Settings" using the "Add Platform" button.

A new window will appear in which you need to click on Web site and choose it as your platform.

So on the application settings page, a new section "Website" will appear, in which you can specify the address of your site.

Save the changes, copy the application ID and place it in the plugin settings of your site.

If you have not figured out the setting of the Facebook application, then here is another one short instruction in English with an example for our site:

This Facebook comment plugin has a lot of options to customize. The default settings should work with most sites. However, you can change them at your own discretion and save the changes.

Now you can test whether the new comment system works correctly on your site.

Comment moderation

Since you have admin rights, you will be notified of new comments. You can manage them and decide whether to publish them or not.

You can also add a new moderator in the settings:

We hope this guide has cleared things up and helped you set up Facebook comments for your non-WordPres site yourself.

This time we are making a simple AJAX commenting system. This one will demonstrate how to achieve efficient interoperability between jQuery and PHP/MySQL using JSON. The system works in such a way that added comments are placed on the page without completely reloading it, giving the feeling of running the site only on the user's computer, thereby avoiding the need to wait for some time required to reload the page with the added comment.

Here is a rough demo of what we plan to implement:

Step 1 - XHTML

First, let's take a look at the comment markup. This code is generated by PHP in a comment, which we are going to look at in an instant.

Demo.php

Name
July 30, 2010

A comment

The div of the avatar class contains a hyperlink corresponding to the avatar (if the user specified a valid link to the avatar when submitting a comment), let's say from gravatar.com. Well, we will come back to this when we work with PHP. Finally, we have the name and time also in DIVs, as well as the comment, i.e. the text itself in the paragraph.

Another important element in the XHTML part is the comment submission form itself (all fields except the URL field are required).

Demo.php

Add a comment

Step 2 - PHP

PHP handles the connection to the MySQL database and creates the comment markup. Also, the receive ends with AJAX and inserts the comment into the comments table. You can see the code that prints out the page comments below.

Demo.php /* / Select all comments and populate the $comments array */ $comments = array(); $result = mysql_query("SELECT * FROM comments ORDER BY id ASC"); while($row = mysql_fetch_assoc($result)) ( $comments = new Comment($row); )

The MySQL query selects all records from the database and populates the $comments array with the comment class object you see below. This array is output after the script is executed.

Demo.php /* / Print comments one by one */ foreach($comments as $c)( echo $c->markup(); )

Each comment has a markup() method that generates the HTML code to print the page. You can see this method and class below.

The class takes a row from the database (fetched with mysql_fetch_assoc()) and stores it in the $data variable. It is available only to methods of this class and cannot be accessed from outside.

Comment.class.php - Step 1 class Comment ( private $data = array(); public function __construct($row) ( /* / Constructor */ $this->data = $row; ) public function markup() ( / */ This method outputs XHTML comment markup */ // Create an alias so we don't // have to write $this->data data each time: $d = &$this->data; $link_open = ""; $link_close = ""; if($d["url"])( // If the person filled in the URL when adding a comment // Define the hyperlink $link_open = ""; $link_close = ""; ) // Time conversion $d[ "dt"] = strtotime($d["dt"]); // Required for default Gravatar images: $url = "http://".dirname($_SERVER["SERVER_NAME"]. $_SERVER["REQUEST_URI "])."/img/default_avatar.gif"; return "

".$link_open." ".$link_close."
".$link_open.$d["name"]. $link_close."

".$d["body"]."

"; }

This script uses Gravatar to show avatars in comments. For those who haven't used Gravatar, this is a very useful service that allows you to associate an avatar with your email address. The avatar can be easily taken by passing the hash over md5().

Notice on line 39 above it - the script tries to figure out the URL it's on and determines the exact address of the default_avatar.gif image. This GIF is passed to Gravatar via an md5 hash, so if an avatar was found at that email address, a fallback stock image is displayed instead.

Comment.class.php - Step 2 public static function validate(&$arr) ( /* / This method is used to validate data / passed via AJAX. / / This returns true/false depending / on the data is valid, and is filled in / The $arr array is passed as paremter / (note the ampersand above) / Either valid input, or error messages.*/ $errors = array(); $data = array(); // Using the filter_input function introduced in PHP 5.2.0 if(!($data["email"] = filter_input(INPUT_POST,"email",FILTER_VALIDATE_EMAIL))) ( $errors["email"] = "Please enter a valid Email. "; ) if(!($data["url"] = filter_input(INPUT_POST,"url",FILTER_VALIDATE_URL))) ( // If the URL field does not match the invalid URL $url = ""; ) // Using filters with custom // callback function: if(!($data["body"] = filter_input(INPUT_POST,"body",FILTER_CALLBACK, array("options"=>"Comment::validate_text")))) ( $errors[ "body"] = "Comment error."; ) if(!($data["name"] = filter_input(INPUT_POST,"name",FILTER_CALLBACK, array("options"=>"Comment::validate_text")))) ( $errors["name"] = " Name error."; ) if(!empty($errors))( //If there are errors, write $errors to the $arr array: $arr = $errors; return false; ) foreach($data as $k=>$ v)( $arr[$k] = mysql_real_escape_string($v); ) // Make sure emails are in lowercase // (for a valid Gravatar hash): $arr["email"] = strtolower(trim($arr[ "email"])); return true; )

validate() is defined as static in the manner described above. This means that it can be called directly as Comment::validate() without having to create an object of this class. This method is not a validation of the input, which is submitted via AJAX.

This method uses the new filter functions that are available in PHP 5.2.0. This allows us to easily validate and filter any input that is passed to the script. For example filter_input(INPUT_POST, "URL", FILTER_VALIDATE_URL) means we are checking $_POST["url"] is a valid URL. If so, then the function returns the value of the variable, otherwise the returns are false.

This is very useful, because until now, we had to use our own regular expressions to validate the data. Also, another benefit is that this data is taken before any configuration-specific transformations (such as magic quotes).

We also have the ability to specify a custom function that is going to apply some more advanced data modifications, as seen in lines 31 and 37.

Comment.class.php - Step 3 private static function validate_text($str) ( /* / This method is used internally as FILTER_CALLBACK */ if(mb_strlen($str,"utf8") , ", etc...) and convert // Newlines to
tags: $str = nl2br(htmlspecialchars($str)); // Remove newlines that are left $str = str_replace(array(chr(10),chr(13)),"",$str); return $str; )

The last method is validate_text , which we pass as a callback function. It escapes all special HTML characters, effectively preventing them from XSS attacks. It also replaces character strings with
lines.

Submit.php /* / This array will be populated with either / The data that was sent to the script, or / Error messages: /*/ $arr = array(); $validates = Comment::validate($arr); if($validates) ( /* Everything is fine, insert into the database: */ mysql_query(" INSERT INTO comments(name,url,email,body) VALUES ("".$arr["name"]."", " ".$arr["url"]."", "".$arr["email"]."", "".$arr["body"]."")"); $arr["dt" ] = date("r",time()); $arr["id"] = mysql_insert_id(); /* / Data in $arr is inserted by query, / but unescaped text, / so we use stripslashes / for all array elements: /*/ $arr = array_map("stripslashes",$arr); $insertedComment = new Comment($arr); /* Output markup */ echo json_encode(array("status"=>1, "html" =>$insertedComment->markup())); ) else ( /* Print error messages */ echo "("status":0,"errors":". json_encode($arr).")"; )

submit.php receives the comment data as an AJAX request. It validates it and returns a JSON object of either the XHTML markup that was successfully rendered, or a list of error messages. jQuery uses the status property to determine whether to display error messages or add a page markup comment.

You can see two examples below.

In this lesson, I'll show you how to make comments in HTML, CSS, PHP. Comments are text that is not visible on a web page. They are used for all kinds of explanations, reminders, descriptions for webmasters, which allows you to structure the document. Comments are indispensable when debugging code, they allow you to quickly navigate the markup of a web page and find the desired block. Comments are often used to debug HTML code. For example, you can temporarily comment out a specific block of code so that it is not executed, and if necessary, it is easy to restore it.

Comments in HTML

In HTML, comments are formed using characters:. Thus, any text between these characters is a comment. Consider an example:

Comments in CSS

Comments in CSS are created using the characters: /* and */. To create a comment, you just need to put the web page code between these characters:

/* Beginning of block with styles for Body*/ body ( background: #efeded; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px; ) /* End of block with styles for Body*/

Comments in PHP

Comments in PHP can be single-line or multi-line:

1) Single-line comments in PHP are created using the characters: //. It is enough just to put this character before the line and it will be commented out. This option is used when the comment consists of only one line.

2) To implement multi-line comments, the following symbols are used: /* and */. This option is useful if the comment spans multiple lines.

Thus we have learned to



tell friends