Page 1 of 1

ROI Form for anyone that needs something like this

Posted: Thu Nov 17, 2011 10:40 pm
by vflflyer
I welcome any ideas on how to improve this as I am just learning PHP!

index.php page:

Code: Select all

<?php

$directory = $_SERVER['PHP_SELF'];

$directory = str_replace("/index.php", "", $directory);


?>

<html>
<head>

<meta HTTP-EQUIV="REFRESH" content="0; url=<?php echo $directory ?>/process.php">
</head>
<body>
</body>
</html>
process.php page:

Code: Select all

<?php

$daily_impressions = $_POST["daily_impressions"];

$program_name = $_POST["program_name"];

$percent_viewers = $_POST["percent_viewers"];

$percent_interested = $_POST["percent_interested"];

$percent_might_convince = $_POST["percent_might_convince"];

$average_margin = $_POST["average_margin"];

$monthly_advertising_cost = $_POST["monthly_advertising_cost"];
// -----------------------Start Removing Special Characters Accept for Decimal Points -------------------------------

$daily_impressions = preg_replace('/[^0-9]*/','', $_POST['daily_impressions']);
$percent_viewers = preg_replace('/[^0-9]*/','', $_POST['percent_viewers']);
$percent_interested = preg_replace('/[^0-9]*/','', $_POST['percent_interested']);
$percent_might_convince = preg_replace('/[^0-9]*/','', $_POST['percent_might_convince']);
$average_margin = preg_replace('/[^0-9.]*/','', $_POST['average_margin']);
$monthly_advertising_cost = preg_replace('/[^0-9.]*/','', $_POST['monthly_advertising_cost']);

// ----------------------- End Removing Special Characters Accept for Decimal Points -----------------------------------


if ($_POST["submit"] == "Calculate" && (empty($daily_impressions) || empty($percent_viewers) || empty($percent_interested)  || empty($percent_might_convince)  || empty($average_margin)  || empty($monthly_advertising_cost)))
{
$emptyvar = 1;
}

if ($_POST["submit"] == "Calculate" && $emptyvar != 1)
{
$projected_return_percent = (($daily_impressions * ($percent_viewers / 100) * ($percent_interested / 100) * ($percent_might_convince / 100) * $average_margin * 30) - $monthly_advertising_cost) * 100 / $monthly_advertising_cost;

$projected_return_dollars = (($daily_impressions * ($percent_viewers/100) * ($percent_interested/100) * ($percent_might_convince/100) * $average_margin) * 30)- $monthly_advertising_cost;

$projected_return_percent = round($projected_return_percent, 2);
$projected_return_dollars = round($projected_return_dollars, 0);
}

$directory = $_SERVER['PHP_SELF'];

$directory = str_replace("/process.php", "", $directory);

?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ROI Calculator</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
</head>
<body id="main_body" >
	<div id="form_container">
    	<h1><a>ROI Calculator</a></h1>
<form id="form" class="inflatables"  method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <div class="form_description">
  	<h2>ROI Calculator</h2>
      <p>Calculate the Return On your Investment.</p>
  </div>
<ul >
<?php

if ($_POST["submit"] == "Calculate" && (empty($daily_impressions) || empty($percent_viewers) || empty($percent_interested)  || empty($percent_might_convince)  || empty($average_margin)  || empty($monthly_advertising_cost)))
{
  echo "<p style=\"text-align:center\"><font color=\"red\">Error: You Must fill in all numberic fields</font></p>";

$emptyvar = 1;
}

?>
<li id="li_1" >
<label class="description" for="element_1">Program Name </label>
<div>
<input id="element_1" name="program_name" class="element text large" type="text" maxlength="255" value="<?php echo $program_name ?>"/>
</div>
</li>
<li id="li_2" >
<label class="description" for="element_2">Daily impressions at selected location (traffic)? </label>
<div>
<input id="element_2" name="daily_impressions" class="element text medium" type="text" maxlength="255" value="<?php echo $daily_impressions ?>"/>
</div>
</li>
<li id="li_3" >
<label class="description" for="element_3">% How many people actually see the display)? </label>
</label>
<div>
<input id="element_3" name="percent_viewers" class="element text medium" type="text" maxlength="255" value="<?php echo $percent_viewers ?>"/>
</div>
</li><li id="li_4" >
<label class="description" for="element_4">Of those, what % do you think are in the market for your product?</label>
<div>
<input id="element_4" name="percent_interested" class="element text medium" type="text" maxlength="255" value="<?php echo $percent_interested ?>"/>
</div>
</li><li id="li_5" >
<label class="description" for="element_5">% you might convince to buy from you? </label>
<div>
<input id="element_5" name="percent_might_convince" class="element text medium" type="text" maxlength="255" value="<?php echo $percent_might_convince ?>"/>
</div>
</li><li id="li_6" >
<label class="description" for="element_6">What is your average margin per sale? </label>
<div>
<input id="element_6" name="average_margin" class="element text medium" type="text" maxlength="255" value="<?php echo $average_margin ?>"/>
</div>
</li><li id="li_7" >
<label class="description" for="element_7">Monthy cost of advertising at this location? </label>
<div>
<input id="element_7" name="monthly_advertising_cost" class="element text medium" type="text" maxlength="255" value="<?php echo $monthly_advertising_cost ?>"/>
</div>
</li><li class="buttons">
<input id="saveForm" class="button_text" type="submit" name="submit" value="Calculate" />
</li>
</ul><br />

<?php
if ($emptyvar != 1 && ($projected_return_percent != 0 || $projected_return_dollars != 0))
{
// ------------ Daily impressions at selected location (traffic)? ------------------	
  echo "<strong style=\"font-size:10pt\">According to our Department of Highways and The Traffic Audit
Bureau, the daily impressions (or circulation) on the proposed board is:<font color=\"red\"> ", number_format($daily_impressions, 0, ',', ','),"</font></strong><br /><br />";

// -------------- % Viewers (How many people actually see the display)? ------------------
$results = ($daily_impressions * $percent_viewers)/100;
  echo "<strong style=\"font-size:10pt\">Conservatively, if you agree that just<font color=\"red\"> " . $percent_viewers . "%</font> actually see your ad on this board, that means that:<font color=\"red\"> ", number_format($results, 0, ',', ','),"</font> were exposed to your advertisement. </strong><br /><br />";
  
// ------- % Interested in your product or in the market for your --------------  
$results = ($daily_impressions * $percent_viewers * $percent_interested)/10000;
  echo "<strong style=\"font-size:10pt\">Suppose that<font color=\"red\"> " . $percent_interested . "%</font> of those people are actually in the market for your product. That's:<font color=\"red\"> ", number_format($results, 0, ',', ','),"</font></strong><br /><br />";  

// ------------------- % You might convince to buy from you? ------------------------
$results = ($daily_impressions * $percent_viewers * $percent_interested * $percent_might_convince)/1000000;
  echo "<strong style=\"font-size:10pt\">Suppose that<font color=\"red\"> " . $percent_might_convince . "%</font> of those people decide to buy from you. That's:<font color=\"red\"> ", number_format($results, 0, ',', ','),"</font></strong><br /><br />";

// -------------------- What is average margin per sale? ----------------------------
$results = ($daily_impressions * $percent_viewers * $percent_interested * $percent_might_convince * $average_margin)/1000000;  echo "<strong style=\"font-size:10pt\">According to your average profit per sale of:<font color=\"red\"> $", number_format($average_margin, 2, '.', ','),"</font> Your total profit per day would be:<font color=\"red\"> $", number_format($results, 0, '.', ',')," </font></strong><br /><br />";


// ------------------------------- Profit per month --------------------------------
$results = ($daily_impressions * $percent_viewers * $percent_interested * $percent_might_convince * $average_margin)*30/1000000;
  echo "<strong style=\"font-size:10pt\">And per month would be:<font color=\"red\"> $", number_format($results, 2, '.', ',')," </font></strong><br /><br />";

// ----------------------- Proposed Investment ---------------------------------------
  echo "<strong style=\"font-size:10pt\">Your proposed outdoor investment of:<font color=\"red\"> $", number_format($monthly_advertising_cost, 2, '.', ',')," </font></strong><br /><br />";


// --------------------------- Projected Returns --------------------------------
  echo "<strong style=\"font-size:10pt\">Means that you would have a monthly return of:<font color=\"red\"> $", number_format($projected_return_dollars, 2, '.', ','),"</font><br /><br />";

  echo "<strong style=\"font-size:10pt\">Which makes your outdoor Return on Investment:<font color=\"red\"> " . $projected_return_percent . "%</font></strong>";

}
	 

?>
</form>

</div>
        <img id="bottom" src="<?php echo $directory ?>/bottom.png" alt="">
</body>
</html>