Thursday, 14 March 2019

Creating Valid RSS feed in PHP



RSS Feature in content based website has been used by number of website owner around the world for get information of latest content information from online website.

RSS is a very simple broadcast feature which is used from introduce updated information to number of receivers.

RSS will automatically send changed content regularly to the user.

If you seen orange icon on many website, that means that website has provide content through RSS feed.

So, in this post we will make dynamic RSS feed by using PHP script from data has been fetch from Mysql database. In this post you can find out how to create your own custom RSS by using PHP script and Mysql. Before we will discuss which tag has been used to make RSS feed and what is use of that tag in RSS feed and lastly we will seen how to use PHP script for implementing dynamic RSS feed in PHP.

RSS feed must add following fields.

<?xml ?> - RSS feed must be start with this XML tag in which we have to define version of XML.

<rss> - Below XML tag we have start define RSS feed by using this tag, in which we can define version of RSS.

<channel> - In RSS feed first we have to create channel by using this tag.

<title> - RSS feed name has been define under this <title> tag.

<link> - RSS feed link has been define in <link> tag.

<description> - A short description of RSS feed must be set under this <description> tag.

<language> - We must have to define RSS feed language, which has been define under tag. For example, American English language RSS feed we have to write "en-us", here en is ISO-639 language code and us stand for ISO-3166 country codes.

All above tag has been in RSS feed header section, but all below tag will be used in body section of RSS feed which is under each item comes in the feed.

<item> - RSS feed item has been define by this tag.

<title> - RSS feed item title has been set under this tag.

<link> - Link of each item has been define under this <link> tag.

<description> - Under this tag we can define short description of each item, and description must contain at least 300 or more characters.

<pubDate> - Publication date of each item has been define under this <pubDate> tag and date must be ISO 8601 or RFC822 standard format.

<guid> - In RSS feed, we have to provide unique id for each item, which has been define under this <guid> tag.

<dc:creator>
- Name of the author has been define under this tag.
<enclosure> - Any media attachment like image or video link has been define under this tag, here we have also define size of attachment with it's mime type also.

Optional: <category> - This is optional tag in RSS feed and here we can define category of each item.

This is complete description of RSS feed tag, below you can find source code of How to create dynamic RSS feed in PHP with Mysql database.






Mysql Table



--
-- Table structure for table `tbl_post`
--

CREATE TABLE `tbl_post` (
  `id` mediumint(8) UNSIGNED NOT NULL,
  `post_title` text,
  `post_description` text,
  `author` varchar(255) DEFAULT NULL,
  `datetime` datetime DEFAULT NULL,
  `post_image` varchar(150) DEFAULT NULL,
  `post_url` varchar(150) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for table `tbl_post`
--
ALTER TABLE `tbl_post`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `tbl_post`
--
ALTER TABLE `tbl_post`
  MODIFY `id` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;



index.php



<?php

//index.php

$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");

$query = "SELECT * FROM tbl_post ORDER BY id DESC";

$statement = $connect->prepare($query);

$statement->execute();

$result = $statement->fetchAll();

header("Content-Type: text/xml;charset=iso-8859-1");

$base_url = "http://localhost/tutorial/how-to-create-dynamic-rss-feed-in-php/";

echo "<?xml version='1.0' encoding='UTF-8' ?>" . PHP_EOL;
echo "<rss version='2.0'>".PHP_EOL;
echo "<channel>".PHP_EOL;
echo "<title>Feed Title | RSS</title>".PHP_EOL;
echo "<link>".$base_url."index.php</link>".PHP_EOL;
echo "<description>Cloud RSS</description>".PHP_EOL;
echo "<language>en-us</language>".PHP_EOL;

foreach($result as $row)
{
 $publish_Date = date("D, d M Y H:i:s T", strtotime($row["datetime"]));
 $image_size_array = get_headers($base_url . "images/".$row["post_image"], 1);
 $image_size = $image_size_array["Content-Length"];
 $image_mime_array = getimagesize($base_url . "images/".$row["post_image"]);
 $image_mime = $image_mime_array["mime"];
 
 echo "<item xmlns:dc='ns:1'>".PHP_EOL;
 echo "<title>".$row["post_title"]."</title>".PHP_EOL;
 echo "<link>".$base_url."blog/".$row["post_url"]."/</link>".PHP_EOL;
 echo "<guid>".md5($row["id"])."</guid>".PHP_EOL;
 echo "<pubDate>".$publish_Date."</pubDate>".PHP_EOL;
 echo "<dc:creator>".$row["author"]."</dc:creator>".PHP_EOL;
 echo "<description><![CDATA[".substr($row["post_description"], 0, 300) ."]]></description>".PHP_EOL;
 echo "<enclosure url='images/".$row["post_image"]."' length='".$image_size."' type='".$image_mime."' />".PHP_EOL;
 echo "<category>PHP tutorial</category>".PHP_EOL;
 echo "</item>".PHP_EOL;
}

echo '</channel>'.PHP_EOL;
echo '</rss>'.PHP_EOL;

?>


Reading RSS Feed with PHP



Above we have seen how to build RSS Feed using Dynamic Mysql data in PHP. Here you can find Reading of XML RSS Feed data using PHP script. There are many website which has use XML RSS feed for received data from other site for display on their website. There is one benifits of using XML RSS feed data is that content receiver site has not store other website data on their website, and benifits to content website owner is that he can publish their website content on other website by add content into RSS feed.

So, there benifits to both content publisher and content provider. This is main benifits of RSS feed. Below you can find complete PHP Source code of reading of RSS feed in PHP.


<?php

//read.php

$feed_url = "http://localhost/tutorial/how-to-create-dynamic-rss-feed-in-php/index.php";

$object = new DOMDocument();

$object->load($feed_url);

$content = $object->getElementsByTagName("item");


?>

<!DOCTYPE html>
<html>
 <head>
  <title>How to Read RSS Feed in PHP</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
 </head>
 <body>
  <div class="container">
   <br />
   <h2 align="center">How to Read RSS Feed in PHP</h2>
   <br />
   <?php
    
   foreach($content as $row)
   {
    echo '<h3 class="text-info">' . $row->getElementsByTagName("title")->item(0)->nodeValue . '</h3>';
    echo '<hr />';
    echo '
    <div class="row">
     <div class="col-md-3">
      <p>'.$row->getElementsByTagName("pubDate")->item(0)->nodeValue.'</p>
      <br />
      <img src="'.$row->getElementsByTagName("enclosure")->item(0)->attributes["url"]->nodeValue.'" class="img-responsive img-thumbnail" />
     </div>
     <div class="col-md-9">
      <p align="right"><b><i>By '.$row->getElementsByTagNameNS("ns:1", "*")->item(0)->nodeValue.'</i></b></p>
      <br />
      <p>'.$row->getElementsByTagName("description")->item(0)->nodeValue.'</p>
     </div>
    </div>
    ';
    echo '<br />';
    echo '<span class="label label-primary">'.$row->getElementsByTagName("category")->item(0)->nodeValue.'</span>';
    echo '<br />';
    echo '<hr />';
    echo '<br />';
    
   }

   ?>
  </div>
 </body>
</html>

Tuesday, 12 March 2019

Ajax jQuery Based Star Rating System in Codeigniter



In this post, We will learn to make 5 Star Rating System in Codeigniter by using Ajax jQuery and Mysql database. Five Star Rating will allows to user to submit their review on any product or service or business unit is useful or not. User can send Live Rating on product and on web page it will get live result of result on web page without refresh of web page. Because here we will use Ajax with Codeigniter framework for developing Star Rating application. This feature is very common in most of the e-commerce who want to sale their product online. Based on rating user can get idea which product is good based on multiple user review.

In this system User can rate the business unit or product based on their quality of product or services, advantages of product etc. So, that rating will helpful to other user who want to use particular business unit service or buy product then based on other user review or rating new user will idea regarding of listed product on e-commerce site.

In this tutorial, we will use pure jquery and Ajax code for make Star rating in Codeigniter, here we have not use any jQuery plugin for implement star rating system in Codeigniter. This is dynamic star rating system, in which rating will be display on average rating of all user, which we have been make in Codeigniter using Ajax jQuery. In this system when use click on particular number of Star then Ajax request has been send to Codeigniter controller, which will insert rating data of particular product in Mysql table. This is simple Codeigniter Ajax based Star rating system script which will help you to developed 5 star rating feature in your Codeigniter web application. Below you can find complete step by step process of How to build Star rating in Codeigniter using Ajax jquery and Mysql.






Step 1 - Create Table


First, We have to create table in Mysql database, in this we have to make business and rating. This two table we will for build dynamic star rating system.


--
-- Database: `testing`
--

-- --------------------------------------------------------

--
-- Table structure for table `business`
--

CREATE TABLE `business` (
  `id` int(11) NOT NULL,
  `business_name` varchar(300) NOT NULL,
  `address` text NOT NULL,
  `product` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `business`
--

INSERT INTO `business` (`id`, `business_name`, `address`, `product`) VALUES
(1, 'Fog Harbor Fish House', 'Fisherman\'s Wharf, North Beach/Telegraph Hill\r\nPier 39\r\nSan Francisco, CA 94133\r\nPhone number (415) 421-2442', 'Seafood, Bars'),
(2, 'The House', 'North Beach/Telegraph Hill\r\n1230 Grant Ave\r\nSan Francisco, CA 94133\r\nPhone number (415) 986-8612', 'Asian Fusion'),
(3, 'Barnzu', 'Tenderloin\r\n711 Geary St\r\nSan Francisco, CA 94109\r\nPhone number (415) 525-4985', 'Korean, Tapas Bars'),
(4, 'Brenda French Soul Food', 'Tenderloin\r\n652 Polk St\r\nSan Francisco, CA 94102\r\nPhone number (415) 345-8100', 'Breakfast & Brunch, French, Soul Food'),
(5, 'The Salzburg', 'Russian Hill, North Beach/Telegraph Hill\r\n663 Union St\r\nSan Francisco, CA 94133', 'Austrian'),
(6, 'Marufuku Ramen', 'Lower Pacific Heights, Japantown\r\n1581 Webster St\r\nSan Francisco, CA 94115\r\nPhone number (415) 872-9786', 'Seafood, Seafood Markets, Live/Raw Food');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `business`
--
ALTER TABLE `business`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `business`
--
ALTER TABLE `business`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- Table structure for table `rating`
--

CREATE TABLE `rating` (
  `rating_id` int(11) NOT NULL,
  `business_id` int(11) NOT NULL,
  `rating` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `rating`
--

INSERT INTO `rating` (`rating_id`, `business_id`, `rating`) VALUES
(1, 6, 3),
(2, 6, 5),
(3, 6, 3),
(4, 5, 3),
(5, 5, 2),
(6, 5, 5),
(7, 5, 5),
(8, 5, 5),
(9, 5, 1),
(10, 3, 5),
(11, 4, 3),
(12, 4, 5),
(13, 4, 3),
(14, 4, 5),
(15, 1, 3),
(16, 1, 1),
(17, 1, 2),
(18, 1, 5),
(19, 1, 5),
(20, 2, 4);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `rating`
--
ALTER TABLE `rating`
  ADD PRIMARY KEY (`rating_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `rating`
--
ALTER TABLE `rating`
  MODIFY `rating_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;


Step 2 - Database Connection


In second step, we have to make database connection in Codeigniter framework, for this we have to go to application/config/database.php and in this file we have to define Mysql database configuration details.


<?php

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'username' => 'root',
 'password' => '',
 'database' => 'testing',
 'dbdriver' => 'mysqli',
 'dbprefix' => '',
 'pconnect' => FALSE,
 'db_debug' => (ENVIRONMENT !== 'production'),
 'cache_on' => FALSE,
 'cachedir' => '',
 'char_set' => 'utf8',
 'dbcollat' => 'utf8_general_ci',
 'swap_pre' => '',
 'encrypt' => FALSE,
 'compress' => FALSE,
 'stricton' => FALSE,
 'failover' => array(),
 'save_queries' => TRUE
);


?>


Step 3 - Controllers (Star_rating.php)


After this we have to make Star_rating.php controller file under application/controllers folder. In this class we have create following method for handle HTTP request.

__construnct() - This magic method will execute this block of code on every time when object of this class has been created.

index() - This is the root method of this Controllers class, when in browser we have enter base_url/star_rating, then it will execute this method which will load application/views/star_raing.php file as an output in browser.

fetch() - This method will display all business unit data on web page with Star rating. This method has received Ajax request for display all product details with star rating on web page.

insert() - This method will insert rating data by using models method. This method also received Ajax request for insert user rating data into Mysql table.


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Star_rating extends CI_Controller {

 public function __construct()
 {
  parent::__construct();
  $this->load->model('star_rating_model');
 }

 function index()
 {
  $this->load->view('star_rating');
 }

 function fetch()
 {
  echo $this->star_rating_model->html_output();
 }

 function insert()
 {
  if($this->input->post('business_id'))
  {
   $data = array(
    'business_id'  => $this->input->post('business_id'),
    'rating'   => $this->input->post('index')
   );
   $this->star_rating_model->insert_rating($data);
  }
 }

}
?>


Step 4 - Models (Star_rating_model.php)


In Codeigniter framework, models class has been mainly used for do all Mysql database operation. This class method will be execute from controller class method. In this class we have use following make following method for star rating system.

get_business_data() - This method will return all business table data.

get_business_rating($business_id) - This method will return average rating of business based on $business_id argument.

html_output() - This method will convert all business data with rating in html format, this method has been called fetch method of Star_rating controllers class.

insert_rating() - This method will insert user rating data into rating Mysql table. This method has been called from insert() method of Star_rating controller.


<?php
class Star_rating_model extends CI_Model
{
 function get_business_data()
 {
  $this->db->order_by('id', 'DESC');
  return $this->db->get('business');
 }

 function get_business_rating($business_id)
 {
  $this->db->select('AVG(rating) as rating');
  $this->db->from('rating');
  $this->db->where('business_id', $business_id);
  $data = $this->db->get();
  foreach($data->result_array() as $row)
  {
   return $row["rating"];
  }
 }

 function html_output()
 {
  $data = $this->get_business_data();
  $output = '';
  foreach($data->result_array() as $row)
  {
   $color = '';
   $rating = $this->get_business_rating($row["id"]);
   $output .= '
   <h3 class="text-primary">'.$row["business_name"].'</h3>
   <ul class="list-inline" data-rating="'.$rating.'" title="Average Rating - '.$rating.'">
   ';
   for($count = 1; $count <= 5; $count++)
   {
    if($count <= $rating)
    {
     $color = 'color:#ffcc00;';
    }
    else
    {
     $color = 'color:#ccc;';
    }

    $output .= '<li title="'.$count.'" id="'.$row['id'].'-'.$count.'" data-index="'.$count.'" data-business_id="'.$row["id"].'" data-rating="'.$rating.'" class="rating" style="cursor:pointer; '.$color.' font-size:24px;">&#9733;</li>';
   }
   $output .= '</ul>
   <p>'.$row["address"].'</p>
   <label style="text-danger">'.$row["product"].'</label>
   <hr />
   ';
  }
  echo $output;
 }

 function insert_rating($data)
 {
  $this->db->insert('rating', $data);
 }
}

?>




Step 5 - Views (star_rating.php)


In Codeigniter framework views file has been used for display HTML output on web page. In this file we have use jQuery function for load business data on web page. In jQuery function, it has use Ajax request for display business and rating data on web page. Same way for insert rating data, here also we have use Ajax. So, all operation will be perform without refresh of web page. For star rating effect we have use jQuery code. This all source code you can find below.


<html>
<head>
    <title>Star Rating in Codeigniter using Ajax jQuery</title>
    
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    
</head>
<body>
 <div class="container box">
  <h3 align="center">Star Rating in Codeigniter using Ajax jQuery</h3>
  <br />
  <span id="business_list"></span>
 </div>
</body>
</html>

<script>
$(document).ready(function(){

 load_data();

 function load_data()
 {
  $.ajax({
   url:"<?php echo base_url(); ?>star_rating/fetch",
   method:"POST",
   success:function(data)
   {
    $('#business_list').html(data);
   }
  })
 }

 $(document).on('mouseenter', '.rating', function(){
  var index = $(this).data('index');
  var business_id = $(this).data('business_id');
  remove_background(business_id);
  for(var count = 1; count <= index; count++)
  {
   $('#'+business_id+'-'+count).css('color', '#ffcc00');
  }
 });

 function remove_background(business_id)
 {
  for(var count = 1; count <= 5; count++)
  {
   $('#'+business_id+'-'+count).css('color', '#ccc');
  }
 }

 $(document).on('click', '.rating', function(){
  var index = $(this).data('index');
  var business_id = $(this).data('business_id');
  $.ajax({
   url:"<?php echo base_url(); ?>star_rating/insert",
   method:"POST",
   data:{index:index, business_id:business_id},
   success:function(data)
   {
    load_data();
    alert("You have rate "+index +" out of 5");
   }
  })
 });

 $(document).on('mouseleave', '.rating', function(){
  var index = $(this).data('index');
  var business_id = $(this).data('business_id');
  var rating = $(this).data('rating');
  remove_background(business_id);
  for(var count = 1; count <= rating; count++)
  {
   $('#'+business_id+'-'+count).css('color', '#ffcc00');
  }
 });

});
</script>


This is the complete step by step process for create Star rating system in Codeigniter using Ajax jquery. So, you can learn something new in Codeigniter framework. If you want to see demo this post, you can find below demo link.






Friday, 8 March 2019

Latest Web Design Trends 2019

Latest Web Design Trends 2019


There is a thin line between following the crowd and being creative especially when you are in the web designing industry. As a website designer, your uniqueness lies in being creative but going against the trend is undoubtedly out of question. So the ideal course of action should be to thoughtfully follow the trend deploying your creativity delivering an outcome that supersedes the expectations. Striking off the right balance between both happens to be the key for staying trendy and up-to-date.

So how do we identify and decide what’s trendy? Look around!! The trend is more about empathizing with what is loved, what is hated and what attracts us. It is about understanding the emergence and adoption of the how’s and why’s of the trends’. What matters here is to ensure that any and every new trend must offer dynamic feasibility to establish a swifter and stronger connection between the concerned parties.

With every new year, new trends knock the door. Similarly, with the onset of 2019, global experts have come up with their inputs regarding the latest web design trends. Let us walk through the path and unravel some of them in web design formats that you, too, can incorporate in your projects ahead.

3-Dimensional Illustrations


There is an idea hidden in almost every old fashioned form and that holds true for this one. It is nothing but a modernized form of mix and match of the old and new 3D concept. Not content with what already existed, the designers have tried to add further elements like depth and realism to the graphics to actually create an effectual illusion. An illusion that smudges the borderline between digital and human worlds facilitating the users to understand what one wants to convey.

The introduction of varied 3-D elements creates an imaginary space that can help the audience time travel to the future. It gives them a chance to witness a manipulative web structure capable of meeting their demands and influencing them to stay connected. One such example is the Kaspersky's project of Earth 2050, which gives the users a realistic view in its thoughts and goals.

Outlining Graphics


There is 50:50 to this one. While you are writing something that needs to be empathized upon like header names, the brand, the website name – the outlining effect or graphics can definitely make it bolder, interactive, alluring and be food for thought for few. With just outlines doing it for you, the visible half text and the other half being erased gives a feeling of dominance and revolution that the brand can bring.

The outlined style is striking the chord, the one that cannot be ignored, even by the busiest eyes. There is a hidden charisma in such shapes, that tempts the mind to evaluate what’s written, automatically giving birth to a curiosity of discovering the business further.

Helveticization of Brand Identity


2018 saw many companies like Uber, MailChimp and more worldwide changing their business logos giving way to a WHY! They moved to be pleasingly unconventional brand identities to more simple yet sophisticated ones leading to a so-called Helvetica version. With companies moving from noticeably idiosyncratic to ubiquitously voiceless boasting off more serious, less-serif logos is a characteristic of a company attaining maturity. 2019 is no exception and is expected to see more such transformations across the globe with companies displaying their mature version.

Illustrations of Thoughts in Abstract Style


Restricting yourself to looking what your immediate competitors or peers are up to, takes away your opportunity to look out for better sources of illustration inspiration. How about giving your thoughts an abstract style to illustrate the ideas that are more expressive and allusive pieces across the web? This abstract way of illustrating the ideas and thoughts is picking up the pace with more and more creative potential being displayed by the designers.

So it is time to replace flat styles of expressing your thoughts and purpose with designs inclined towards more abstract styles. Leave behind straightforward illustrations and deploy something that is more fascinating, luring and creative to share with the world, Your Ideas, the and Thoughts!

Bold Typography


Keeping it bold is necessary but what good palettes do? There has been synchronization in the color palettes being used by competitors in the same industry however 2019 is expected to notice companies shifting to following more approachable, softer and subtle color palettes. On the other hand, you will continue to see companies gaining attention with bolder, opinionated and much-saturated color schemes. Illustrations will continue to form a crucial part in every design to effectually humanize the brand to develop a strong and impactful connect with the audience.


Massive, Screen Dominating Text


The specialists have finally been able to convince what value content holds in the overall web designing and related processes. There have been instances wherein the websites are truly following and setting the trend to give center stage to textual content. What you aim to convey to the audience that forms may be your header shouldn’t be small as a snail rather massive that dominates the screen. The year 2019 trending arts are demanding the headers to be exclusively large - large enough for multiple eyes to catch the hint.

Homogeneous Hero


You are unique in your industry but whether it is your website or your competitors’ – they are all the same. Every business is trying to sell its uniqueness in the same way yet considering themselves different from the crowd. But the year 2018 saw this trend getting metamorphosed. Good news!! 2019 marks the launch of the homogeneous hero with the web pages being broken into separate grids offering clarity to the respective elements.

This homogeneity emphasizes on placing the elements like the heading, the sub-headings, the call-to-action and more in an asymmetrical manner to bring out the actual context of what we are, what we do and much more. With the entire page broken down into grids allows you enough space to make the strong elements more pronounced than others.

Go Beyond the Prejudices of Typography Styles


Focusing on the fact of creating trendy styles that go on to become a landmark in your path, you have to look beyond the prejudices and be open to diverse options. Opt for creating your own typography styles to make and mark the difference. For instance include disappearing texts, fringes in the borders, sacked fonts, and more than top the list of different typographies in 2019.

Author Bio


The author is a renowned freelance website designer in Delhi who has gained expertise in designing by understanding the trend and delivering some marvelous websites incorporating the fad and latest web design trends.

Wednesday, 6 March 2019

PHP Ajax Live Search with Multiple Value



Do you know Search Live Data is required feature for filter Mysql to view only required data which you want to required. So, In this tutorial, we will learn how to make simple application in which we can search or filter Mysql database data with single search query with multiple value. On question aris how to search data with multiple search value in single click. For this here we will use Bootstrap input tags plugin for multiple search value in single search with Ajax jQuery and PHP.

Bootstrap Tags Input plugin is a jQuery plugin for converting input texts into tags format. After converting into tags we can enter another text which will also convert into tags. So, in single input text we will enter multiple tags, and this tags we will use for search data in Mysql database using PHP with Ajax. So, when we have click on search button, then at that time it will send multiple search query at the same time. So, this way we can use Bootstrap tags plugin for search live data with multiple search value and filter data according to multiple search values.

For initialize this plugin functionality, we have to just add data-role="tagsinput" attribute in our input fields, it will automatically convert input fields into tag input fields. So, it is very easy to use this plugin in our existing web development environment.

Here we will step by step learn How to use Bootstrap Tags Input plugin for make Live Data Search feature with Multiple values using Ajax with PHP and Mysql. For this here we will make live demo in which we can search customer data with multiple value.

At the server side how can we use multiple search value for filter data or make search mysql query with multiple input search value. For, this here we will use REGEX operator, this is another type of pattern based operator which is based on regular expression. Which we will use for search data with multiple search value. Below you can find complete step by step of PHP Ajax Live Data search with Multiple Values using Bootstrap Tags Input plugin.




PHP Ajax Live Search with Multiple Value


Step 1 - Mysql Database Table


For implement Live Data Search Functionality with Multiple Search Value for filter data, for this first we want to make tbl_customer table in mysql database. For this you have to run following SQL query for create table in your Mysql Database. This script will not only make tbl_customer but also it will insert some data also. So, it is easy for you implement this feature.


USE `testing`;

/*Table structure for table `tbl_customer` */

DROP TABLE IF EXISTS `tbl_customer`;

CREATE TABLE `tbl_customer` (
  `CustomerID` int(11) NOT NULL AUTO_INCREMENT,
  `CustomerName` varchar(250) NOT NULL,
  `Gender` varchar(30) NOT NULL,
  `Address` text NOT NULL,
  `City` varchar(250) NOT NULL,
  `PostalCode` varchar(30) NOT NULL,
  `Country` varchar(100) NOT NULL,
  PRIMARY KEY (`CustomerID`)
) ENGINE=MyISAM AUTO_INCREMENT=146 DEFAULT CHARSET=latin1;

/*Data for the table `tbl_customer` */

insert  into `tbl_customer`(`CustomerID`,`CustomerName`,`Gender`,`Address`,`City`,`PostalCode`,`Country`) values 
(1,'Maria Anders','Female','Obere Str. 57','Berlin','12209','Germany'),
(2,'Ana Trujillo','Female','Avda. de la Construction 2222','Mexico D.F.','5021','Mexico'),
(3,'Antonio Moreno','Male','Mataderos 2312','Mexico D.F.','5023','Mexico'),
(4,'Thomas Hardy','Male','120 Hanover Sq.','London','WA1 1DP','United Kingdom'),
(5,'Paula Parente','Female','Rua do Mercado, 12','Resende','08737-363','Brazil'),
(6,'Wolski Zbyszek','Male','ul. Filtrowa 68','Walla','01-012','Poland'),
(7,'Matti Karttunen','Male','Keskuskatu 45','Helsinki','21240','Finland'),
(8,'Karl Jablonski','Male','305 - 14th Ave. S. Suite 3B','Seattle','98128','United States'),
(9,'Paula Parente','Female','Rua do Mercado, 12','Resende','08737-363','Brazil'),
(10,'John Koskitalo','Male','Torikatu 38','Oulu','90110','Finland'),
(39,'Ann Devon','Female','35 King George','London','WX3 6FW','United Kingdom'),
(38,'Janine Labrune','Female','67, rue des Cinquante Otages','Nantes','44000','Finland'),
(37,'Kathryn Segal','Female','Augsburger Strabe 40','Ludenscheid Gevelndorf','58513','Germany'),
(36,'Elizabeth Brown','Female','Berkeley Gardens 12 Brewery','London','WX1 6LT','United Kingdom'),
(30,'Trina Davidson','Female','1049 Lockhart Drive','Barrie','ON L4M 3B1','Canada'),
(31,'Jeff Putnam','Male','Industrieweg 56','Bouvignies','7803','Belgium'),
(32,'Joyce Rosenberry','Female','Norra Esplanaden 56','HELSINKI','380','Finland'),
(33,'Ronald Bowne','Male','2343 Shadowmar Drive','New Orleans','70112','United States'),
(34,'Justin Adams','Male','45, rue de Lille','ARMENTIERES','59280','France'),
(35,'Pedro Afonso','Male','Av. dos Lusiadas, 23','Sao Paulo','05432-043','Brazil'),
(100,'Kathryn Segal','Female','Augsburger Strabe 40','Ludenscheid Gevelndorf','58513','Germany'),
(101,'Tonia Sayre','Female','84 Haslemere Road','ECHT','AB32 2DY','United Kingdom'),
(102,'Loretta Harris','Female','Avenida Boavista 71','SANTO AMARO','4920-111','Portugal'),
(103,'Sean Wong','Male','Rua Vito Bovino, 240','Sao Paulo-SP','04677-002','Brazil'),
(104,'Frederick Sears','Male','ul. Marysiuska 64','Warszawa','04-617','Poland'),
(105,'Tammy Cantrell','Female','Lukiokatu 34','HAMEENLINNA','13250','Finland'),
(106,'Megan Kennedy','Female','1210 Post Farm Road','Norcross','30071','United States'),
(107,'Maria Whittaker','Female','Spresstrasse 62','Bielefeld Milse','33729','Germany'),
(108,'Dorothy Parker','Female','32 Lairg Road','NEWCHURCH','HR5 5DR','United Kingdom'),
(109,'Roger Rudolph','Male','Avenida Julio Saul Dias 78','PENAFIEL','4560-470','Portugal'),
(110,'Karen Metivier','Female','Rua Guimaraes Passos, 556','Sao Luis-MA','65025-450','Brazil'),
(111,'Charles Hoover','Male','Al. Tysiaclecia 98','Warszawa','03-851','Poland'),
(112,'Becky Moss','Female','Laivurinkatu 6','MIKKELI','50120','Finland'),
(113,'Frank Kidd','Male','2491 Carson Street','Cincinnati','KY 45202','United States'),
(114,'Donna Wilson','Female','Hallesches Ufer 69','Dettingen','73265','Germany'),
(115,'Lillian Roberson','Female','36 Iolaire Road','NEW BARN','DA3 3FT','United Kingdom'),
(144,'Stephen M. Menzies','Male','577 Hartway Street','Bruie','57325','United States'),
(143,'Nikki G. Pascual','Female','4291 Kinney Street','Agawam','1001','United States'),
(141,'Alpha A. Brookover','Female','3542 Trainer Avenue','Kilbourne','62655','United States'),
(142,'Austin D. Salem','Male','1184 Farland Street','Brockton','2401','United States'),
(140,'Bianca A. Carone','Female','1777 Elkview Drive','Hialeah','33012','United States'),
(139,'Stephen M. Menzies','Male','577 Hartway Street','Bruie','57325','United States'),
(138,'Nikki G. Pascual','Female','4291 Kinney Street','Agawam','1001','United States'),
(136,'Alpha A. Brookover','Female','3542 Trainer Avenue','Kilbourne','62655','United States'),
(137,'Austin D. Salem','Male','1184 Farland Street','Brockton','2401','United States'),
(145,'Bianca A. Carone','Female','1777 Elkview Drive','Hialeah','33012','United States');


index.php


This is main file in this tutorial. On this page we have included all required library like jQuery, Bootstrap and Bootstrap Tag Input library. In this file you can file HTML code and jQuery code of this tutorial. For initialize Bootstrap Tag Input plugin on input textbox, we have to just add data-role="tagsinput" attribute in it. For display customer data here we have make one table, and in this tag data will be filled by using jquery function load_data(). This function has been use Ajax request for received customer data in json format and convert that json data to HTML using jQuery code.


<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Live Data Search using Multiple Tag in PHP with Ajax</title>  
  <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.css" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput-typeahead.css" />
  <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tagsinput/0.8.0/bootstrap-tagsinput.min.js" crossorigin="anonymous"></script>
  
  <style>
  .bootstrap-tagsinput {
   width: 100%;
  }
  </style>
 </head>
 <body>
  <div class="container">
   <br />
   <br />
   <br />
   <h2 align="center">Live Data Search using Multiple Tag in PHP with Ajax</h2><br />
   <div class="form-group">
    <div class="row">
     <div class="col-md-10">
      <input type="text" id="tags" class="form-control" data-role="tagsinput" />
     </div>
     <div class="col-md-2">
      <button type="button" name="search" class="btn btn-primary" id="search">Search</button>
     </div>
    </div>
   </div>
   <br />
   <div class="table-responsive">
    <div align="right">
     <p><b>Total Records - <span id="total_records"></span></b></p>
    </div>
    <table class="table table-bordered table-striped">
     <thead>
      <tr>
       <th>Customer Name</th>
       <th>Gender</th>
       <th>Address</th>
       <th>City</th>
       <th>Postal Code</th>
       <th>Country</th>
      </tr>
     </thead>
     <tbody>
     </tbody>
    </table>
   </div>
  </div>
  <div style="clear:both"></div>
  <br />
  
  <br />
  <br />
  <br />
 </body>
</html>


<script>
$(document).ready(function(){
 
 load_data();

 function load_data(query)
 {
  $.ajax({
   url:"fetch.php",
   method:"POST",
   data:{query:query},
   dataType:"json",
   success:function(data)
   {
    $('#total_records').text(data.length);
    var html = '';
    if(data.length > 0)
    {
     for(var count = 0; count < data.length; count++)
     {
      html += '<tr>';
      html += '<td>'+data[count].CustomerName+'</td>';
      html += '<td>'+data[count].Gender+'</td>';
      html += '<td>'+data[count].Address+'</td>';
      html += '<td>'+data[count].City+'</td>';
      html += '<td>'+data[count].PostalCode+'</td>';
      html += '<td>'+data[count].Country+'</td></tr>';
     }
    }
    else
    {
     html = '<tr><td colspan="5">No Data Found</td></tr>';
    }
    $('tbody').html(html);
   }
  })
 }

 $('#search').click(function(){
  var query = $('#tags').val();
  load_data(query);
 });

});
</script>





fetch.php

This is PHP script file, which has handle ajax request for fetch data from Mysql database. In this script it has check there is any value of $_POST['query'] variable. If this variable has some value, then it will make Mysql query for filter data from tbl_customer table, and for search query it has use REGEX operator for search data with multiple value. But $_POST['query'] variable has no any value, then it will make query for fetch all data from tbl_customer table.


<?php

//fetch.php

$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");

$output = '';

$query = '';

if(isset($_POST["query"]))
{
 $search = str_replace(",", "|", $_POST["query"]);
 $query = "
 SELECT * FROM tbl_customer 
 WHERE CustomerName REGEXP '".$search."' 
 OR Address REGEXP '".$search."' 
 OR City REGEXP '".$search."' 
 OR PostalCode REGEXP '".$search."' 
 OR Country REGEXP '".$search."'
 ";
}
else
{
 $query = "
 SELECT * FROM tbl_customer ORDER BY CustomerID
 ";
}

$statement = $connect->prepare($query);
$statement->execute();

while($row = $statement->fetch(PDO::FETCH_ASSOC))
{
 $data[] = $row;
}

echo json_encode($data);

?>


This is complete source code of Ajax PHP Live Data search with Multiple values by using Bootstrap Tags Input plugin. So, you have learn something new from this post. You can also check demo of this tutorial by click on below Demo link.






Web Development with PHP – Usages, Advantages, and Disadvantages

Web Development with PHP – Usages, Advantages, and Disadvantages


Having a website is a priority need for not only businesses but for individuals too who wants to build a notable presence on the web space and reach to people. Design and development are the two key steps in the website or web application development. PHP or Hypertext Preprocessor is now one of the leading programming languages, which is commonly used in website development by the majority of the programmers.

PHP is primarily a general-purpose scripting language which is a server-side programming platform, which runs on a web server designed to run dynamic web pages and web applications. As a web development platform, PHP is a very secured, reliable, and fast tool which puts forth many advantages and made accessible to all as an open-source programming language.

Some key facts about PHP development are:

  • PHP supports databases as MySQL, Oracle, and Sybase, etc.
  • PHP is compatible with the web application servers as Apache and IIS etc.
  • PHP can run on various platforms like Windows or Linux etc.
  • PHP is so flexible and user-friendly to handle due to its easy development functions and simple syntax.
  • PHP can support DBMS systems and many open-source databases as well.
  • PHP as an open-source platform is compatible with Joomla, Drupal, OsCommerce, and Typo3, etc.

PHP in Business web development


Businesses wanted to develop their website without any hassle and maintained well over time. As far as PHP is concerned, the LAMP development suite can make the business website functional, strong, and secured. LAMP is the combination of Linux, Apache, MySQL, and PHP, which is so popular in developing modern and affordable websites.



Advantages of PHP


PHP has many advantages as a web development platform; let's explore a few top benefits here.

1. PHP is a cross-platform programming language


PHP applications can be run on different platforms. The major advantage of PHP is that the developers need not have to worry about the OS at the user's end. It is a proven fact that PHP code can render properly on all existing operating systems now. Moreover, PHP is a scripting language, and all the hosting services support it.

2. Easy to use


Even those who are new to web development find PHP as a very easy to learn and handle programming language. It can be learned in a short span of time, and the syntaxes are so simple to handle. PHP syntax is quite similar to the C programming language. Individuals familiar with C programming can easily understand and create PHP scripts.

3. Speed and performance


A crucial aspect of web development is speed. It is not only important in terms of ensuring optimum user satisfaction, but it is essential in terms of ensuring better search engine ranking also now. A fast loading website is important for businesses to enhance their online business. Users are so busy, and they don't like to wait for the slow loading sites to show up. Instead, they tend to switch on to an alternate site instantly. So, developers largely use PHP as it is so quick and digital marketing friendly.

4. Powerful libraries


Another big advantage of PHP is that it's developed and maintained by a consortium of skilled and experienced PHP developers, and there is a huge supporting community also. An extensive library of PHP with an immense collection of functional modules makes PHP very developer friendly.

5. Stable


PHP is out there as a strong web development platform for more than two decades now. This is a long timeframe in terms of quick changing technology industry. Developers have worked on this application throughout this time period and to enhance the features and users of this application. A lot of bugs have been identified and debugged, and PHP has now become optimally streamlined and simplest to use. Based on all these facts, this programming platform is now deemed to be highly stable.



Disadvantages of PHP


In fact, while we list the advantages of PHP, it is also important to check out a major disadvantage also of this platform.

Weak in nature


While preprocessor hypertext language was first created, it was thought to be handling smaller applications, so with its built, it is tough for the developers to program any larger applications using PHP. As this language is not having a modular approach, the larger applications planed on this platform are tough to build and maintain. However, it is surely an excellent language for websites and to develop smaller web applications.

Choosing a PHP developer for your web development project


As we have seen above, PHP is a popular programming platform, and there are plenty of web developers out there who are working on PHP. To reap the best benefits for PHP in your business website development projects, you may try to hire the top PHP web development services at budget costs. With several options to choose, here are a few tips which may be helpful in choosing the right PHP development service.

Consider experience


Before considering a PHP website design service, you should check the experience of the developer/team in web application development. It is ideal for checking the portfolio of the service to see if they have handled projects similar to yours. The developer should be aware of various technical elements to be considered for the efficient development of your website.

Technical knowledge


It requires various technical skills to become a successful website developer. Along with high-end coding skills on PHP, the professional also should have high proficiency in MySQL, HTML, CSS, JavaScript, XML, AJAX, jQuery, Bootstrap, etc. to become a full-fledged website developer. The developers also should have hands-on skills in solving the security issues and also to plan and design the application database. In addition to all these, the modern-day developers also should have knowledge in on-page SEO elements and optimizing page loading speed, etc.

It is good to look for a stable provider than a random freelancer to develop your business website in order to ensure ongoing support and maintenance needs. To ensure optimum performance of your website, it is also important to get a reliable and secure web hosting service also. Considering all above facts, there is no doubt that PHP is one of the strongest and elegant options for your business web development project as far as you get the best developers to handle your project and offer ongoing support.

Saturday, 2 March 2019

PHP cURL for Downloading File From Url



This is one more post on Download Remote Files from URL, but in this blog we will use PHP cURL library for download file from URL. By using cURL library we will make simple feature like Save file from URL to server by using PHP script. In one of our previous post, in which we have discuss PHP Download file from URL using file_get_contents() method. But in this post we have use cURL for PHP Download file from URL. Because this method is still available in PHP 7 also.

Here we will make simple form for dynamically download file from entered URL using PHP and cURL. First we will write validation code for check enter string is valid url or not. If it is valid then it will proceed for downloading process using PHP cURL Library.

There are following cURL Library and function we will use for Download image from Url in PHP.

curl_init() - This method will initialize a cURL session.

curl_setopt() - This method will set option for transer cURL data. In this method we have use three option. First CURLOPT_URL option for fetch data from URL. Second is CURLOPT_RETURNTRANSFER option, it will return true on send data from URL in string format and third is CURLOPT_SSLVERSION.

curl_exec() - This method will execute cURL session.

curl_close() - This method will close cURL session.

There are some other function we has use with this cURL library, which you can find under source code. Below you can find complete source code of this post.







Source Code



<?php

//index.php

$image = '';
$error = '';

if(isset($_POST["download"]))
{
 if(empty($_POST["url"]))
 {
  $error = '<p class="text-danger"><b>Enter URL</b></p>';
 }
 else if(!filter_var($_POST["url"], FILTER_VALIDATE_URL))
 { 
  $error = '<p class="text-danger"><b>Invalid URL</b></p>';
 }
 else
 {
  $url = $_POST["url"];
  $start = curl_init();
  curl_setopt($start, CURLOPT_URL, $url);
  curl_setopt($start, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($start, CURLOPT_SSLVERSION, 3);
  $file_data = curl_exec($start);
  curl_close($start);
  $file_path = 'download/' . uniqid() . '.jpg';
  $file = fopen($file_path, 'w+');
  fputs($file, $file_data);
  fclose($file);
  $image = '<img src="'.$file_path.'" class="img-thumbnail" width="250" />';
 }
}

?>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Download File from URL using PHP CURL</title>
  <meta content='width=device-width, initial-scale=1, maximum-scale=1' name='viewport'/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
  <style>
  .box
  {
   width:100%;
   max-width:720px;
   margin:0 auto;
  }
  </style>
 </head>
 <body>
  <div class="container">
   <br />
   <h2 align="center">Download File from URL using PHP CURL</h2><br />
   <div class="row">
    <div class="col-md-3">
     
    </div>
    <div class="col-md-9">
     <form method="post">
      <div class="form-group">
       <label>Enter URL</label>
       <input type="text" name="url" class="form-control input-lg" autocomplete="off" />
       <?php echo $error; ?>
      </div>
      <br />
      <br />
      <input type="submit" name="download" value="Download" class="btn btn-info btn-lg" />
      <br />
      <br />
      <?php echo $image; ?>
     </form>
     <br />
     
    </div>
   </div>
  </div>
  <div style="clear:both"></div>
  <br />
  
  <br />
  <br />
  <br />
 </body>
</html>







Wednesday, 27 February 2019

How to use jqBootstrapValidation for Validate Form with Ajax PHP



This one more Webslesson post on How to validate form data using jQuery plugin. Now in this post we have use jqBoostrapValidation plugin for validate form data and make spam free contact form with Ajax and PHP. In one of previous post, we have use parsleyjs for form data validation and submit form data using Ajax. Here also we will show you how to validate form data by using jqBootstraoValidation plugin and submit form data using Ajax with PHP.

jqBootstrapValidation is a jQuery plugin for validate bootstrap form data. It mainly display validation error in help-block of Bootstrap library class. It is a simple form validation plugin, which mainly used with Bootstrap library. If you have use Bootstrap library for your front end use, then it will help you in form validation. Because it has used Bootstrap library element as users type. Validation of Form data is a headache of every programmer, but if you have used bootstrap library, then this plugin will helpful to validate form data.

This plugin has used HTML5 validator attributes on html field, and it has used data attributes for display error. If you want to set any input, which data has required for submit form, then at that time you can simply used requred="required" attribute, then this plugin will directly scan this HTML5 attributes for validate that input field. Now question aris how can we display error of that validation, then in this plugin used data-validation-required-message attributes has been used for display required validation error.

After this suppose you want to validate email fields data, for this you have to just used input="email" this plugin will automatically generates error if email fields data in not in proper email format.

Same way, we want to validate mobile number in form field, then at that time we can use pattern attributes like pattern="^[0-9]{10}$" this pattern will validate mobile number which must be in number format with the length 10 digit if data is not in this format then it will display error. For display pattern validation error, this plugin has use data-validation-pattern-message this data attribute for display pattern mismatch validation error. If you want to get details documentation of this plugin, you can get here.






Source Code


index.php



<!DOCTYPE html>
<html>
 <head>
  <title>Contact Form Validation using jqBootstrapValidation with Ajax PHP</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jqBootstrapValidation/1.3.6/jqBootstrapValidation.js"></script>
  <style>
  .box
  {
   max-width:600px;
   width:100%;
   margin: 0 auto;;
  }
        .form-group p
        {
            color:#a94442;
        }
  </style>
 </head>
 <body>
  <div class="container">
   <br />
   <h3 align="center">Contact Form Validation using jqBootstrapValidation with Ajax PHP</h3>
   <br />
   <form id="simple_form" novalidate="novalidate">

    <div class="control-group">
                    <div class="form-group mb-0 pb-2">
                        <input type="text" name="contact_name" id="contact_name" class="form-control form-control-lg" placeholder="Name" required="required" data-validation-required-message="Please enter your name." />
                        <p class="text-danger help-block"></p>
                    </div>
                </div>

                <div class="control-group">
                    <div class="form-group">
                        <input type="email" name="contact_email" id="contact_email" class="form-control form-control-lg" placeholder="Email Address" required="required" data-validation-required-message="Please enter your email address." />
                        <p class="text-danger help-block"></p>

                    </div>
                </div>

                <div class="control-group">
                    <div class="form-group">
                        <input type="tel" name="contact_mobile" id="contact_mobile" class="form-control form-control-lg" placeholder="Phone Number" required="required" data-validation-required-message="Please enter your phone number." pattern="^[0-9]{10}$" data-validation-pattern-message="10 digits needed" />
                        <p class="text-danger help-block"></p>

                    </div>
                </div>

                <div class="control-group">
                    <div class="form-group">
                        <textarea name="contact_message" id="contact_message" class="form-control form-control-lg" rows="5" placeholder="Message" required="required" data-validation-required-message="Please enter a message."></textarea>
                        <p class="text-danger help-block"></p>
                    </div>
                </div>
                <br>
                <div id="success"></div>
                <div class="form-group">
                 <button type="submit" class="btn btn-primary" id="send_button">Send</button>
                </div>
   </form>
  </div>
 </body>
</html>

<script>
$(document).ready(function(){
 
    $('#simple_form input, #simple_form textarea').jqBootstrapValidation({
     preventSubmit: true,
     submitSuccess: function($form, event){     
      event.preventDefault();
      $this = $('#send_button');
      $this.prop('disabled', true);
      var form_data = $("#simple_form").serialize();
      $.ajax({
       url:"send.php",
       method:"POST",
       data:form_data,
       success:function(){
        $('#success').html("<div class='alert alert-success'><strong>Your message has been sent. </strong></div>");
        $('#simple_form').trigger('reset');
       },
       error:function(){
        $('#success').html("<div class='alert alert-danger'>There is some error</div>");
        $('#simple_form').trigger('reset');
       },
       complete:function(){
        setTimeout(function(){
         $this.prop("disabled", false);
         $('#success').html('');
        }, 5000);
       }
      });
     },
    });

});
</script>





send.php



<?php

//send.php

if(isset($_POST["contact_name"]))
{
 require 'class/class.phpmailer.php';
 $mail = new PHPMailer;
 $mail->IsSMTP();
 $mail->Host = 'smtpout.secureserver.net';

 $mail->Port = '80';

 $mail->SMTPAuth = true;
 $mail->Username = 'xxxx';
 $mail->Password = 'xxxx'; 
 $mail->SMTPSecure = '';
 $mail->From = $_POST['contact_email'];
 $mail->FromName = $_POST['contact_name'];
 $mail->AddAddress('web-tutorial@programmer.net');
 $mail->WordWrap = 50;
 $mail->IsHTML(true);

 $mail->Subject = 'New Business Enquiry from ' . $_POST['contact_name'];
 $message_body = $_POST["contact_message"];
 $message_body .= '<p>With mobile number ' . $_POST["contact_mobile"] . '</p>';
 $mail->Body = $message_body;

 if($mail->Send())
 {
  echo 'Thank you for Contact Us';
 }
}

?>

This is complete step by process of how use jqBootstrapValidation library for validate form data with Ajax request and PHP script.