How to search in specific content type in drupal 7

Suppose you have created a content type named as “testimonial”. Now the requirement is to for search for a value “hello” under field name “title” then you can do so by using the below query. Please make sure that you have the “Entity API”  module enabled.

 


$searchkeyword = $_REQUEST['keyword'];
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', '[The machine name for your content type]') // in our case it is "testimonial"
->propertyCondition('title', $searchkeyword)
->propertyCondition('status', 1)
->fieldCondition('field_active_status', 'value', 'active',"=") // here you have to define your where condition on additional fields if required
->execute();

Validate checkbox array and prefill with selected value on validation error in laravel 5

Say for example you have your checkbox field code in your twig file as below:-

@foreach ($serviceList as $servloop)
<div class=”checkbox”>
<label>
<input type=”checkbox” name=”services[]” value=”{{$servloop->service_id}}” {{ ( is_array(old(‘services’)) && in_array($servloop->service_id, old(‘services’)) ) ? ‘checked ‘ : ” }} />
{{$servloop->service_name}}
</label>
</div>
@endforeach

Controller file code

Validation Rule will be as below:-

$rules = [
‘services’ => ‘required|min:1’,  // min:1 means atleast one should be selected
];

$customMessages = [
‘services.required’ => ‘Select the service you will need from us, for and during the Expo.’,
];

 

 

 

Validate date format mm/dd/yyyy by using jquery validation library

First add the custom method to the validation library as below. Can you put this code in your jquery validation file or in your page where you want to validate the date, just before setting your validation rule for your form.

$.validator.addMethod(“dateFormat”,
 function (value, element) {
 return value.match(/^(?:(0[1-9]|1[012])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](19|20)[0-9]{2})$/);
 },“Please enter a date in the format mm/dd/yyyy.”);

Now suppose you are using a datepicker or input field to accept the date in mm/dd/yyyy format like 02/21/2018 as example. You can validate it as below;

 

<form id="your-form-id">
<input id="submission_date" name="submission_date" type="text" />
<input type="submit" value="submitForm" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js">
 <script type="text/javascript">

$("#your-form-id").validate({
 rules: {
 submission_date: {
 required: true,
 dateFormat: true,
 },
 },
 messages: {
 submission_date: {
 required: "Please select or enter the submission date!!.",
 dateFormat: "Submission date should in the format mm/dd/yyyy.",
 },
 },
 errorPlacement: function(error, element) {
 error.insertAfter(element);
 },
 submitHandler: function (formName) {
 formName.submit();
 }
 });
 </script>

Validate date format mm/dd/yyyy in jquery or javascript

<script type="text/javascript">

function isValideDate(datavalue){
 var regexValidDate = /^(?:(0[1-9]|1[012])[\/.](0[1-9]|[12][0-9]|3[01])[\/.](19|20)[0-9]{2})$/;
 return regexValidDate.test(datavalue);
 }

var dateToCheck = '06/01/2011',

if(isValideDate(dateToCheck)){

alert("Given date is valid as per the format of MM/dd/YYYY");

}else{

alert("Given date is not valid as per the format of MM/dd/YYYY");

}

</script>

 

Redirect to another page after a specific time interval

<html>
<body>
<h1>Welcome to my Website</h1>
<h4 id=”msg”>You will be redirected to another page in 5 seconds!</h4>
<script type=”text/javascript”>
function countDown(i, callback) {
callback = callback || function(){};
var int = setInterval(function() {
//document.getElementById(“displayDiv”).innerHTML = “Number: ” + i;
document.getElementById(“msg”).innerHTML = “You will be redirected to backend page in “+i+” seconds!”;
i– || (clearInterval(int), callback());
}, 1000);
}
setTimeout(function(){
countDown(5, function(){
window.location=”[Give your absolute or relative url to redirect]”;
});
}, 3000);
</script>
</body>
</html>

How to create tar archive file in linux

The below command will create a tar archive file whatevername_yougive.tar for a directory /path/of/directory/to/archive in current working directory.

See the example below.

tar cvf whatevername_yougive.tar /path/of/directory/to/archive

The options detail are explained as below
c – Creates a new .tar archive file.
v – Verbosely show the .tar file progress.
f – File name type of the archive file.

Similarly to create tar.gz file

tar cvzf whatevername_yougive.tar.gz /path/of/directory/to/archive

To untar or uncompress a tar file check here