Wednesday, October 10, 2018

Front End Post Submission Form in WordPress


The process for creating a front-end submission form for posts, pages, or custom post types is actually quite simple, even though it is often thought of as being very difficult. There are just two major components to a front-end submission form:
  1. An HTML form for the data to be entered into
  2. A function that listens for the form submission and then processes the submitted data
The code written in the video, which consists of just two functions, is less than 80 lines and contains everything needed for a pretty decent front-end submission form, even if it is pretty basic. It introduces everything you need to know for getting started with building these kinds of forms and opens up the door to countless possibilities.
<?php
function create_post_form() {
ob_start();
if(isset($_GET['post'])) {
switch($_GET['post']) {
case 'successfull':
echo '<p class="success">' . __('Job created', 'gocloud') . '</p>';
break;
case 'failed' :
echo '<p class="error">' . __('Please fill in all the info', 'gocloud') . '</p>';
break;
}
}
?>
<form id="pippin_create_post" action="" method="POST">
<fieldset>
<input name="job_title" id="job_title" type="text"/>
<label for="job_title">Job Title</label>
</fieldset>
<fieldset>
<input name="user_name" id="user_name" type="text"/>
<label for="user_name">Your Name</label>
</fieldset>
<fieldset>
<input name="user_email" id="user_email" type="email"/>
<label for="user_email">Your Email</label>
</fieldset>
<fieldset>
<label for="job_desc">Job Description</label>
<textarea name="job_desc" id="job_desc"></textarea>
</fieldset>
<fieldset>
<input name="inquiry_email" id="inquiry_email" type="email"/>
<label for="inquiry_email">Inquiry Email</label>
</fieldset>
<fieldset>
<?php wp_nonce_field('jobs_nonce', 'jobs_nonce_field'); ?>
<input type="submit" name="job_submit" value="<?php _e('Submit Job Posting', 'gocloud'); ?>"/>
</fieldset>
</form>
<?php
return ob_get_clean();
}
add_shortcode('post_form', 'create_post_form');

function process_post_creation() {
if(isset($_POST['jobs_nonce_field']) && wp_verify_nonce($_POST['jobs_nonce_field'], 'jobs_nonce')) {

if(strlen(trim($_POST['job_title'])) < 1 || strlen(trim($_POST['job_desc'])) < 1) {
$redirect = add_query_arg('post', 'failed', home_url($_POST['_wp_http_referer']));
} else {
$job_info = array(
'post_title' => esc_attr(strip_tags($_POST['job_title'])),
'post_type' => 'jobs',
'post_content' => esc_attr(strip_tags($_POST['job_desc'])),
'post_status' => 'pending'
);
$job_id = wp_insert_post($job_info);

if($job_id) {
update_post_meta($job_id, 'ecpt_postedby', esc_attr(strip_tags($_POST['user_name'])));
update_post_meta($job_id, 'ecpt_posteremail', esc_attr(strip_tags($_POST['user_email'])));
update_post_meta($job_id, 'ecpt_contactemail', esc_attr(strip_tags($_POST['inquiry_email'])));
$redirect = add_query_arg('post', 'successfull', home_url($_POST['_wp_http_referer']));
}
}
wp_redirect($redirect); exit;
}
}
add_action('init', 'process_post_creation');
?>

Note: This article is taken from (https://pippinsplugins.com/custom-front-end-post-submission-form/)

Saturday, June 9, 2018

Measuring the distance between two coordinates in PHP

function distance($lat1, $lon1, $lat2, $lon2, $unit) {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
      return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
  } else {
      return $miles;
  }
}

Results
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>";
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>";
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>";

Note: This code is taken from: http://www.geodatasource.com/developers/php

Tuesday, March 6, 2018

Dreamweaver fatal error XML parsing

Step 1: Close DW, Navigate to C:\User\uruser\AppData\Roaming\Adobe\Dreamweaver CS5\en_US\Configureation\Workspace\ and delete the specific xml file

Re-open DW. DW should auto-create your Workspace layout XML file again. See if it works fine.

PROCEED TO STEP 2 ONLY IF STEP 1 DOESN'T SOLVE THE ISSUE

Step 2: Navigate to C:\Users\useruser\AppData\Roaming\Adobe\Dreamweaver CS5\en-US\Configuration and delete the entire 'CONFIGURATION' folder. Re-open DW. DW should auto-create your configuration folder based on predefined layouts and config options. This will definitely fix your issue.

 Reason for this issue: This issue would have been caused due to a malformed workspace layout configuration. That may happen due to customizations you may have done to the layout/ improper file permissions/ improper shutdown on Windows.

NOTE: Reference link is https://forums.adobe.com/thread/996876

Sunday, March 4, 2018

Remove White space in Dreamweaver

Isn’t it insanely annoying some times when you open a CSS File or a HTML File only to find Dreamweaver has added loads of blank lines, if your CSS is more white space than code then running this script will be very helpful.
I’ve used a tonne of CSS Compressors to fix Dreamweavers fail of blank lines in the past, but most of them do not support CSS 3, and the ones that do – seemingly do not support the transition effect.  This however, works fine with PHP, HTML and CSS (self tested).  So no more tears for those added line breaks in your PHP or CSS, just run this fix!
Open the file in Adobe Dreamweaver, press CTRL+F to load the Find & Replace dialog box (or Edit > Find and Replace).
Do the search on the source code view.
Check the box “Use regular expression” and un-check any other boxes.
Find: [\r\n]{2,}
Replace: \n
The hit “replace all”
It may take a while so fit back and wait whilst your CSS / HTML or PHP Document is flushed of all those annoying line breaks!
NOTE:  This Article is taken from http://www.itsadam.co.uk/dreamweaver-fix-removing-extra-line-breaks-in-css-html-php/

Friday, March 2, 2018

Simple php function to get coordinates from address through google services

Here I am showing you how to get coordinates from address using google api (Thanks to Google). The result will solely depends on how google support it in the future. Because google will set the 1st index result for the most relevant, thus this works quite well in general.
Function in php:
function getCoordinates($address){
 
$address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern
 
 
$response = file_get_contents($url);
 
$json = json_decode($response,TRUE); //generate array object from the response from the web
 
return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']);
 
}


echo getCoordinates('740 Story Rd San Jose CA 95122');



Note*: This article is taken from https://colinyeoh.wordpress.com/2013/02/12/simple-php-function-to-get-coordinates-from-address-through-google-services/

How to get coordinates from address through google services

Here is the code

<!DOCTYPE html>
<html>
<body>
<div id="googleMap" style="width:100%;height:800px;"></div>

<script>
function myMap() {
var mapProp= {
    center:new google.maps.LatLng(51.508742,-0.120850),
    zoom:5,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

google.maps.event.addListener(map, 'click', function(event) {
alert(event.latLng.lat() + ", " + event.latLng.lng());
});

}
</script>

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyADIXqFBFbbBy3fs-IRL-LH1ozRN4QhgJM&callback=myMap"></script>
</body>
</html>

Tuesday, January 23, 2018

Laravel: Access denied for user 'homestead'@'localhost' (using password: YES)

If you have changed your database credentials in .env file as well in database.php file and you still face the problem then use  the below commands.

php artisan config:clear
php artisan cache:clear
php artisan config:cache

and if you face "Laravel 5 Class 'form' not found"
You can also try running the following commands in Terminal or Command:
1. composer dump-auto or composer dump-auto -o
2. php artisan cache:clear
3. php artisan config:clear

How to change the PHP version for subfolders or subdomains

  How to change the PHP version for subfolders or subdomains Setting a specific PHP version for a specific websites, subfolders or subdomain...