When you have to prefix any hard coded value in a text field, like for example in telephone field you have to prefix the country code and dont want the user to remove it, then in that case assign the prefix code in the text field and add the below javascript code code
jQuery("input[name='job-code']").keydown(function(e) {
var oldvalue = jQuery(this).val();
var field = this;
setTimeout(function() {
if (field.value.indexOf('JPC-') !== 0) {
jQuery(field).val(oldvalue);
}
}, 1);
});
<script type=”text/javascript”>
var formChanged = false;
jQuery(window).load(function() { // This is triggered when the entiire page is loaded fully
// form id and all the possible filed type in that form, You can also target by field type, name, class or id
jQuery(‘#FrmIdToTarget input[type=text], #FrmIdToTarget select.form-control’).each(function (i)
{
// console.log(‘a’);
jQuery(this).data(‘initial_value’, jQuery(this).val());
});
function handleFormChanged(formSaveBtnId) {
// alert(‘formSaveBtnId=’+formSaveBtnId);
jQuery(‘#’+formSaveBtnId).removeAttr(‘disabled’);
formChanged = true;
}
function confirmNavigation() {
if (formChanged) {
return confirm(‘You have changes to save, Please save before moving to next tab? Otherwise your changes will be lost!’);
} else {
return true;
}
}
</script>
Sometime there is need to use some plugins in an application and you have the need to customize it UI or functionality to meet your business requirements.
You install the plugins and make the necessary changes to meet the configuration.
Few week later, you discover that your plugins has lost it custom formatting and the custom workflow due to recent upgrade of the plugins version.
Huhh, now what to do.
Option 1: You may look into your past backupfile to restore the plugins from your back up folder to restore the customized codes. This could be risky or not feasible. For example you may not be having the backup of the plugin , secondly you might get it but may be confused on which version you have to restore, because you had made many backup folder.
Option 2: The recommended way is to disable you customized plugins to get auto upgrade. What you need to do is put this below code in your theme functions.php file.
/**
* Implements hook_preprocess_HOOK().
*/
function [theme]_preprocess_webform_confirmation(&$vars) {
if ($vars['webform']->id() == 'put your webform id') {
// Set your custom message here
$markup = t('Thank you for your feedback.');
$vars['message']['#markup'] = $markup;
}
}
/// How to customise the message based on the submitted value
/**
* Implements hook_preprocess_HOOK().
*/
function [theme]_preprocess_webform_confirmation(&$vars)
{
if ($vars['webform']->id() == 'put your webform id')
{
// Get the submitted form value using the below command
$submittedFormValues = $vars['webform_submission']->getRawData();
if($submittedFormValues['field_name'] == 'some condition or value'){
$markup = t('display message 1');
}
else
{
$markup = t('display message 2');
}
// Set your custom message here
$vars['message']['#markup'] = $markup;
}
}
How to use “grep” command in linux or macos to find text inside all files in a folder and including subdirectories
Command for the same is grep -rl "string to search" /absolute-path/to/folder/
-r (or –recursive) option is used to traverse also all sub-directories of /path
-l (or –files-with-matches) option is used to only print filenames of matching files
-i ( for ignore case sensitive)
If you’re looking for lines matching in files, then use the below command
grep -Hrn "string to search" /absolute-path/to/folder/
-H causes the filename to be printed (implied when multiple files are searched)
-r does a recursive search
-n causes the line number to be printed
/absolute-path/to/folder/ can be . (dot) to search in the current directory
Normally when you use contact form 7 plugin , for dropdown select option, there is no option to set blank value for the first option to validate the select field.
For example, what we have in wordpress contact form 7
But in actual scenario, i want to display the label for the first option as “–Select Value–” with empty value.
To make the same change, you can use the dropdown code as below
[select* your_field_name_ class:form-select class:required first_as_label “–Select Value–” “Yes” “No”]
In the above code “first_as_label” is important parameter. It instruct the plugin to use the first option as label with default empty value. So the generated output look as below
By default apache write the access log and error log in the single file. Later it grow in sizes over days and then when you have to debug you find the issue from the apache log, it become difficult to open and read the file. And over a time, the log size bigger so big that, many of the file editor fail to load the file.
So apache come with a inbuilt program called rotatelogs.
First you need to check if rotatelogs is present on your server or not.
To check if rotatelogs is present type the below command
> whereis rotatelogs
The output of the command will be as below rotatelogs: /usr/bin/rotatelogs /usr/share/man/man8/rotatelogs.8.gz
This “/usr/bin/rotatelogs” indicate that rotatelogs program is present
Now to split your errorlog and accesslog by date, you need to comment the default log format #ErrorLog ${APACHE_LOG_DIR}/error.log #CustomLog ${APACHE_LOG_DIR}/access.log combined
When you have access to the command line and you have the export large database, you will not be able to export from phpmyadmin.
Hence mysql provide you handy method to export the database from the command line. Below are various options, you can use while exporting the database.
——databases – This allows you to specify the databases that you want to backup. You can also specify certain tables that you want to backup. If you want to do a full backup of all of the databases, then leave out this option ——add-drop-database – This will insert a DROP DATABASE statement before each CREATE DATABASE statement. This is useful if you need to import the data to an existing MySQL instance where you want to overwrite the existing data. You can also use this to import your backup onto a new MySQL instance, and it will create the databases and tables for you. ——triggers – this will include the triggers for each dumped table ——routines – this will include the stored routines (procedures and functions) from the dumped databases ——events – this will include any events from the dumped databases ——set-gtid-purged=OFF – since I am using replication on this database (it is the master), I like to include this in case I want to create a new slave using the data that I have dumped. This option enables control over global transaction identifiers (GTID) information written to the dump file, by indicating whether to add a SET @@global.gtid_purged statement to the output. ——user – The MySQL user name you want to use ——password – Again, you can add the actual value of the password (ex. ——password=mypassword), but it is less secure than typing in the password manually. This is useful for when you want to put the backup in a script, in cron or in Windows Task Scheduler. ——single-transaction – Since I am using InnoDB tables, I will want to use this option. ——no-create-db – don’t create database ——no-create-info – don’t create table structure ——extended-insert=FALSE => Each row as seperate insert querry