Need Help with Calculating Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Need Help with Calculating Form

Post by vflflyer »

I do not really know php but am very interested in learning, so I am trying to figure this form out.

I am trying to add a function to this form for when it shows a negative return on investment in percent that it shows the negative sign and calculates it correctly (total dollar return divided by total proposed investment.

I would also like to have the text change on total dollar return and total percent return when they are negative.

I know there is a way to do this but it is beyond me at this point.
A link to the form is at http://www.primair-inflatables.com/roi3/

Hoping someone can help me out

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"];


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)*($percent_interested)*($percent_might_convince)*($average_margin)))/($monthly_advertising_cost/.003);

$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);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Home Outdoor Media: Primair Media</title>
<link href="../style.css" rel="stylesheet" type="text/css">
</head>
<body>

    <div id="form_container">
     <h1 style="background-color:#336699; text-indent:-8000px"><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><p class="guidelines" id="guide_1"><small>Program Name</small></p></li>
<li id="li_2" >
    <label class="description" for="element_2">Daily Impressions (DEC's)</label>
    <div><input id="element_2" name="daily_impressions" class="element text medium" type="text" maxlength="255" value="<?php echo $daily_impressions ?>"/></div><p class="guidelines" id="guide_2"><small>(# of people who drive by your ad daily)</small></p></li>
<li id="li_3" >
    <label class="description" for="element_3">What % of those people do you suppose will see your ad?</label>
    <div><input id="element_3" name="percent_viewers" class="element text medium" type="text" maxlength="255" value="<?php echo $percent_viewers ?>"/></div><p class="guidelines" id="guide_3"><small>(ex: 1, 3, 5, 10)</small></p></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><p class="guidelines" id="guide_4"><small>(ex: 1, 3, 5, 10)</small></p></li>
<li id="li_5" >
    <label class="description" for="element_5">Of those, what % do you think will decide 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><p class="guidelines" id="guide_5"><small>(ex: 1, 3, 5, 10)</small></p></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><p class="guidelines" id="guide_6"><small>What is average margin per sale in $?</small></p></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><p class="guidelines" id="guide_7"><small>Monthy cost of advertising at this location?</small></p></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>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need Help with Calculating Form

Post by Celauran »

Looks to me like your $projected_return_percent calculation is wrong. Should be:

Code: Select all

$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;
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Re: Need Help with Calculating Form

Post by vflflyer »

Celauran wrote:Looks to me like your $projected_return_percent calculation is wrong. Should be:

Code: Select all

$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;
Thanks for that info! :D I do not know what I would do without forums
vflflyer
Forum Newbie
Posts: 11
Joined: Wed Nov 16, 2011 9:41 am

Re: Need Help with Calculating Form

Post by vflflyer »

Celauran wrote:Looks to me like your $projected_return_percent calculation is wrong. Should be:

Code: Select all

$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;
Wow that actually fixed two problems I was having, you are the man!
Post Reply