I made a search bar for my website with bootstrap everything is fine now the problem is that it can also be used when nothing is entered.
So how can i check for that with php and also add a min letter to search.
Just give me a rough idea that what I can do!
well the simplest solution is add required
to it for eg.
<input type = "text" name = "yoursearchbox" required>
If you are using HTML5
you can use required
:
<input type="text" name="search" required>
In PHP
, you can validate in a number of ways, like so:
<?php
if(!isset($_POST["search"]) //The value is not set
||empty(@$_POST["search"]) //The value is empty
||strlen(@$_POST["search"])<1) //The string is shorter than 1 character
{
//Search is empty
}