ONLINE FORM ACTIVATION GUIDE
NOTE: Before making updates, be sure to download a backup of the website files, database, and take a screenshot.

REDIRECT TO NEW PAGE
Step 1. Open the client's website and locate the online form to be activated. It is usually located on the footer area of the website.
Step 2. Add the code snippet below where the online form to be activated is located (e.g. footer.php):
<?php
	$prompt_message = '<span style="color: #FFF;font-size:13px;">Please fill the following:</span>';
	
	if(isset($_POST['submit-btn'])){
		@session_start();
		if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i",stripslashes(trim($_POST['Email']))))
		{ $prompt_message = '<div id="error" style="color: #FFF;font-size:13px;">Please enter a valid email address</div>';}
		else {
			$_SESSION['Name'] = (isset($_POST['Name'])) ? $_POST['Name'] : '';
			$_SESSION['Email'] = (isset($_POST['Email'])) ? $_POST['Email'] : '';
			$_SESSION['Comment'] = (isset($_POST['Comment'])) ? $_POST['Comment'] : '';
			echo "<script type='text/javascript'>window.location='".get_home_url()."?p=POST-ID#main_area';</script>";
		}
	}
?>
Step 3. Update the "POST-ID" (in red text) with the post ID of the page where the form will be redirected.
	To get the post ID of the page you may:
	Step 3.1. Press ctrl + u on your keyboard or right click anywhere on the website then click View Page 	Source. Press ctrl + f on your keyboard and type post-  or div id=post-, the number after the dash sign 	is your post ID.
	Step 3.2. You may log in to your WordPress Dashboard and go to Pages. 
		Step 3.2.1. Locate the Home page and click Edit  or simply click on the page title. On your 			address  bar, locate post=. The number after the equal sign is your post ID.
Step 4. Setup the form. 
	Step 4.1. Set method into "Post", and set action into "#". See example below:
	<form method="post" action="#">
	Step 4.2. Update the field names of the form. Make sure the field names of the form are in sync with 	the $_ SESSION value of the php code snippet and the online form it will be redirected to so the date 	will be passed accordingly.
	Step 4.3. Add required  for the required fields of the form (e.g. Name, Email, and/or Phone number). 	This will make sure that the all required fields are filled in before the client could submit the form.
	Step 4.4. Update or add a name of the submit button. The name should be in sync with the $_POST 	value of the code snippet we added in Step 2.
Step 5. Conduct online form testing.
	Step 5.1. Follow the file path: wp-content/themes/company-themes-folder/ then go to "forms" 		folder then open config.php.
	Step 5.2. Update $testform value from false to true. If value is already true then there's no 			need to change the $testform value. 
 	If the $testform value is true, online form emails will be sent to our testing emails, if the 			$testform value is false, online form emails will be sent to the client's email.
	NOTE: Remember to always set the $testform value to true when conducting online form 			testing so we'll receive the testing emails and make sure that the form is actually working.
	Step 5.3. Click save to save changes made on config.php.
	Step 5.4. Go back to the website and test the online form.
 refer to the PRTool (link below) for the values to input when testing online forms:
http://192.168.1.16/prtool/viewpost/index/T1871725656T5ma34e
	Step 5.5. Revert $testform value to false once done testing.
NOTE: Fix any errors that you may encounter.



























DIRECT SEND FORM
Step 1. Open the client's website and locate the online form to be activated. It is usually located on the footer area of the website.
Step 2. Add the code snippet below where the online form to be activated is located (e.g. footer.php):
<?php
@session_start(); 
require_once 'wp-content/themes/companythemesfolder/forms/FormsClass.php';
$input = new FormsClass();
$formname = 'Home Form';
$prompt_message = '<span style="color:#ff0000;"></span>';

if(isset($_POST['submit_btn'])){
	if(empty($_POST['Full_Name']) ||	
		empty($_POST['Email_Address']) ||	
		empty($_POST['Quick_Message']) ||	
		empty($_POST['secode'])) {
	$asterisk = '<span style="color:#FF0000; font-weight:bold;">*</span>';	
	$prompt_message = '<div id="error">'.$asterisk . ' Required Fields are empty</div>';
	}
	else if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i",stripslashes(trim($_POST['Email_Address']))))
		{ $prompt_message = '<div id="error">Please enter a valid email address</div>';}
	else if($_SESSION['security_code'] != htmlspecialchars(trim($_POST['secode']), ENT_QUOTES)){
		$prompt_message = '<div id="error">Invalid Security Code</div>';
	}else{
		$body = '<div class="form_table" style="width:700px; height:auto; font-size:12px; color:#333333; letter-spacing:1px; line-height:20px; margin: 0 auto;">
			<div style="border:8px double #c3c3d0; padding:12px;">
			<div align="center" style="color:#990000; font-style:italic; font-size:20px; font-family:Arial; margin:bottom: 15px;">('.$formname.')</div>
				<table width="90%" cellspacing="2" cellpadding="5" align="center" style="font-family:Verdana; font-size:13px">';

		foreach($_POST as $key => $value){
			if($key == 'secode') continue;
				elseif($key == 'submit_btn') continue;
			if(!empty($value)){
				$key2 = str_replace('_', ' ', $key);
					if($value == ':') {
					$body .= '<tr><td colspan="2" style="background:#F0F0F0; line-height:30px"><b>'.$key2.'</b></td></tr>';
					}else {				
					$body .= '<tr><td><b>'.$key2.'</b>:</td> <td>'.htmlspecialchars(trim($value), ENT_QUOTES).'</td></tr>';
					}
				}
			}
			$body .= '
		</table>
	</div>
</div>';		
	// for email notification
require_once 'wp-content/themes/company-themes-folder/forms/config.php';
require_once 'wp-content/themes/company-themes-folder/forms/swiftmailer/mail2.php';
	// save data form on database
include 'wp-content/themes/company-themes-folder/forms/savedb2.php';
	// save data form on database
	$subject = $formname ;		
	$attachments = array();
	//name of sender
	$name = $_POST['Full_Name'];
	$result = insertDB($name,$subject,$body,$attachments);		
		
	$templateVars = array('{link}' => get_home_url().'/onlineforms/'.$_SESSION['token'], '{company}' => COMP_NAME);
	Mail::Send($template, 'New Message Notification', $templateVars, $to_email, $to_name, $from_email, $from_name, $cc, $bcc);
	if($result){
		$prompt_message = '<div id="success" style="border:1px solid green; padding:2px; color: green; border-radius:3px; margin-bottom:10px;line-height:18px;text-align:center">Your message has been submitted.  We will get in touch with you as soon as possible.<br/>Thank you for your time.</div>';
		unset($_POST);
	}else {
		$prompt_message = '<div id="error">Failed to send email. Please try again.</div>';
		}
	}	
}
/*************declaration starts here************/
?>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" ></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// validate signup form on keyup and submit
$("#submitform").validate({
	rules: {
		secode: "required"
		},
	messages: {
		secode: ""
		}
	});
	$("#submitform").submit(function(){
		if($(this).valid()){
			$('.load_holder').css('display','block');
			self.parent.$('html, body').animate(
				{ scrollTop: self.parent.$('#myframe').offset().top },
				500
			);
		}
		if(grecaptcha.getResponse() == "") {
			var $recaptcha = document.querySelector('#g-recaptcha-response');
				$recaptcha.setAttribute("required", "required");
				$('.g-recaptcha').addClass('errors').attr('id','recaptcha');
		  }
	});
	$( "input" ).keypress(function( event ) {
		if(grecaptcha.getResponse() == "") {
			var $recaptcha = document.querySelector('#g-recaptcha-response');
			$recaptcha.setAttribute("required", "required");
		  }
	});
});
</script>
<script src='https://www.google.com/recaptcha/api.js'></script>

[starting here until sa last, double check the steps. Nganong nahimo nman lng nuon ug note ang dapat steps unta? Taronga ang arrangement sa mga steps, gpang arrow nman lng ang uban.]
Step 3.  Update the file paths (highlighted in red) found on the php code we added on Step 2.
Step 4. Update the $formname value (highlighted in red) accordingly.
Step 5.  Setup the form. 
	Step 5.1. Set method into "Post", and set action into "#". See example below:
	<form method="post" action="#">
	Step 5.2. Update the field names of the form. Make sure the field names of the form are in sync with 	the $_ SESSION value of the php code snippet and the online form it will be redirected to so the date 	will be passed accordingly.
	Step 5.3. Add required  for the required fields of the form (e.g. Name, Email, and/or Phone number). 	This will make sure that the all required fields are filled in before the client could submit the form.
	Step 5.4. Update or add a name of the submit button. The name should be in sync with the $_POST 	value of the code snippet we added in Step 2.
	Step 5.5. Add Google reCaptcha. You may copy the existing Google reCaptcha from the existing forms of 	the website.
		Step 5.5.1. Follow this path: wp-content/themes/company-themes-folder/ then go to "forms" 			folder then open any form (e.g. contactForm.php).
		Step 5.2.2. Locate the Google reCaptcha by pressing ctrl + f then type:  form_box5.
		Step 5.2.3. Copy the form_box5 div then paste it above the submit button of the online form 			that you're activating. Fix any layout distortion after adding the Google reCaptcha.
Step 6. Create a savedb2.php file and upload it to wp-content/themes/company-themes-folder/forms/ 
Step 6.1. Follow the file path: wp-content/themes/company-themes-folder/ then go to "forms" 		folder then open savedb.php.
Step 6.2. Copy all contents of the savedb.php and paste it to your savedb2.php
Step 6.3. On you savedb2.php, comment out "//require '../../../../wp-config.php';" found on line 4.
Step 6.4. Click save to save savedb2.php.
Step 7.  Create a mail2.php file and upload it to wp-content/themes/company-themes-folder/forms/swiftmailer/ 
Step 7.1. Follow the file path: wp-content/themes/company-themes-folder/forms then go to 	swiftmailer folder then open mail.php.
Step 7.2. Copy all contents of the mail.php and paste it to your mail2.php
Step 7.3. Update $templatePath to the file path where the mailtemplates are found.
Follow this file path to locate the mailtemplates: wp-content/themes/company-themes-folder/forms 	then go to "mailtemplates" folder.
Step 7.4. Click save to save mail2.php.
Step 8. Conduct online form testing.
	Step 8.1. Follow the file path: wp-content/themes/company-themes-folder/ then go to "forms" 		folder then open config.php.
	Step 8.2. Update $testform value from false to true. If value is already true then there's no 			need to change the $testform value. 
 	If the $testform value is true, online form emails will be sent to our testing emails, if the 			$testform value is false, online form emails will be sent to the client's email.
	NOTE: Remember to always set the $testform value to true when conducting online form 			testing so we'll receive the testing emails and make sure that the form is actually working.
	Step 8.3. Click save to save changes made on config.php.
	Step 8.4. Go back to the website and test the online form.
	 refer to the PRTool (link below) for the values to input when testing online forms:
	http://192.168.1.16/prtool/viewpost/index/T1871725656T5ma34e
Step 8.5. Revert $testform value to false once done testing.

NOTE: 
Fix any errors that you may encounter.
Download updated website files and database, take a screenshot.
Push before and after update website files and database, transfer screenshots to "Other" folder.