Monday, February 6, 2017

Functional and Free Landing Pages in WordPress

When designing a website for your business, one of the most important aspects of it is the landing page(s) you created to get the viewers attention.

It is just as important as your home page.

Because from a campaign or even a search engine results page, it will be the most likely page that a potential customer will see for the first time when visiting your website.

Creating landing pages can be accomplished in many different ways depending on your website platform, knowledge level of coding, time constraints, etc.

One of the leading methods to create business websites is to use a platform like WordPress, which will give an average user a ton of tools to get started easily.

There are lots of plugins that are available for all types of landing page creations.

However most of these are costly when you want to get advanced features like tracking, and A/B testing, etc.

I did come across the WordPress Landing Pages by Inbound Now which is a great solution for this.

Firstly, it is free!

Secondly, it provides a lot of functionality in the free version.

Functionality includes:

  • Landing Page creation
  • Call To Action creation
  • Forms creations
  • Leads tracking
  • Conversion tracking
  • Follow up emails
I advise everyone to give it a try as it is free and easy to use.

Sunday, January 31, 2016

How to Create a Basic PHP Form using Classes

We use forms in the web all the time.

This is how we can create a basic form using PHP.

We need to create a class describing the form first.

In a "Form.class" file we can add the following code:

<?php
class Form
{
private $fields = array();
private $actionValue;
private $submit = "Submit Form";
private $Nfields = 0;

function __constructor($actionValue,$submit)
{
$this->actionValue = $actionValue;
$this->submit = $submit;
}

function displayForm()
{
echo "\n<form action='($this->actionValue)' method='POST'>\n";
for($j=1;$j<=sizeof($this->fields);$j++)
{
echo "<p style='clear: left; margin: 0; padding: 0; padding-top: 5px'>\n";
echo "<label style='float: left; width: 20%;'> {$this->fields[$j-1]['label']}: </label>\n";
echo "<input style='width: 200px' type='text' name='{$this->fields[$j-1]['name']}'></p>\n";
}
echo "<input type='submit' value='{$this->submit}' style='margin-left: 25%; margin-top: 10px'>\n";
echo "</form";
}

function addField($name,$label)
{
$this->fields[$this->Nfields]['name'] = $name;
$this->fields[$this->Nfields]['label'] = $label;
$this->Nfields = $this->Nfields + 1;
}
}
?>

To use the form defined above we need to create a php file as follows:

<?php
require_once("Form.class");
echo "<html><head><title>Phone form</title></head><body>";
$phone_form = new Form("process.php","Submit Phone");
$phone_form->addField("first_name", "First Name");
$phone_form->addField("last_name", "Last Name");
$phone_form->addField("phone", "Phone");
echo "<h3>Please fill out the following form:</h3>";
$phone_form->displayForm();
echo "</body></html>";
?>

After adding this to a file named "formexample.php, make sure that you add the "Form.class" file in to the same location.

Run the "form example.php" file and check your newly created form.

Write Data to a File using PHP Functions

A method to write data to a file saved in the local machine using PHP functions.

<?php
//write to file | a-append w-overwrite
function writeToFile($filename,$datatosave,$mode)
{
if (!file_exists($filename))
{
echo "file not found";
echo "<br/>";
}
else
{
$fh = fopen($filename,$mode) or die("Can't open file");
fwrite($fh,$datatosave);
fclose($fh);
echo "File written successfully.";
}
return;
}

echo "<br/>";
writeToFile("test.txt","$today\n","a");
echo "<br/>";

Read Data from a File using PHP

A method to read data from a file using php functions.

<?php
//read from file
function readFromFile($filename)
{
if (!file_exists($filename))
{
echo "file not found";
echo "<br/>";
}
else
{
$fh = fopen($filename,"r") or die("Can't open file");
while(!feof($fh))
{
$line = fgets($fh);
echo "$line<br/>";
}
fclose($fh);
echo "<br/>";
echo "File read successfully.";
}
return;

}

echo "<br/>";
readFromFile("test.txt");
echo "<br/>";
?>

Change Date/Time Zone for PHP Development in a MAMP Installation

We can set the Date/Time zone correctly after a MAMP installation by changing the date.timezone value of the php configuration file.

  • "/MACINTOSH/User/Applications/MAMP/conf/php[version]/php.ini"
  • date.timezone="Asia/Maldives"

Where to Find PHP Errors when using MAMP

When using a MAMP installation as your PHP development environment the errors are not displayed in the browser web page itself.

Instead they are stored in the following location:

  • "/MACINTOSH/User/Applications/MAMP/logs/php_error.log"
You can also find the error logs for MySQL and Apache in the same location in files named "mysql_error_log.err" and "apache_error.log" respectively.

Note: You can also enable error display on the browser webpage itself via changing the following setting in the PHP configuration file, but it is highly not recommended as it displays sensitive information to visitors of the site.
  • /MACINTOSH/User/Applications/MAMP/conf/php[version]/php.ini"
  • find "display_errors" uncommented entry and change it from "Off" to "On"

How to Connect to a MySQL DB and Get Data in PHP using mysqli Syntax

<?php

$dburl = "localhost";
$dbuname = "USERNAME";
$dbpwd = "PASSWORD";
$dbname = "databasename";

$mysqli = new mysqli($dburl, $dbuname, $dbpwd, $dbname);

$query = 'SELECT name, price FROM Products ORDER BY name';

if ($mysqli->errno)
{
printf("Unable to connect to database:<br/> %s", $mysqli->error);
exit();
}
else
{
$result = $mysqli->query($query, MYSQLI_STORE_RESULT);
while(list($name, $price)= $result->fetch_row())
{
printf("Price of %s is: \$%s <br/>", $name, $price);
}
printf("<br>Task Completed.");
}
?>