Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tip Calculator PHP Page #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
53 changes: 0 additions & 53 deletions README-template.md

This file was deleted.

103 changes: 22 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,36 @@
# Tip Calculator in PHP
# PHP-Task - Tip Calculator PHP page

This pre-work incorporates the following 3 required steps and 3 optional steps:
Submitted by: Himanshu Sharma

1. Install PHP
2. Build a Tip Calculator using PHP
3. Submit your code for review
4. Optional: Add support for custom tip percentage
5. Optional: Add support for splitting the tip and total
6. Optional: Extend your app, improve UI, add features
Time spent: 4 hours spent in total

## User Stories

-----
The following **required** functionality is complete:
* [ * ] User can enter a bill amount, choose a tip percentage, and submit the form to see the tip and total values.
* [ * ] Tip percentage choices use a PHP loop to output three radio buttons.
* [ * ] PHP code sets reasonable default values for the form.
* [ * ] PHP code confirms the presence and correct format of submitted values.
* [ * ] Page indicates any form errors which need to be fixed.
* [ * ] Submitted form values are retained when errors or results are shown.

The following **optional** features are implemented:
* [ ] Add support for custom tip percentage
* [ ] Add support for splitting the tip and total

### 1. Install PHP
The following **additional** features are implemented:

Refer to the PHP.net website for general installation instructions.
http://php.net/manual/en/install.php
* [ ] List anything else that you can get done to improve the functionality!

* If you are on a Mac, PHP should already be installed. You can open up the Terminal application and type "php -v" to find out which version you have. PHP 5.5 or later is required for this course, and PHP 7 or later is preferred. If you want to upgrade to a newer version and do not already have experience with package managers like Homebrew, MacPorts, or Fink, then the installer by Liip will be the easiest way to upgrade.
## Video Walkthrough

* If you are on Windows, installing WAMP (http://www.wampserver.com/en/) which includes PHP, Apache, and MySQL may be easier than any of the other installation choices. (The assignment does not use Apache and MySQL, but the course will.)
Here's a walkthrough of implemented user stories:

### 2. Build a Tip Calculator using PHP
<img src='https://github.com/hmnhGeek/php-task/blob/master/img.gif' title='Video Walkthrough' width='' alt='Video Walkthrough' />

* Build an HTML page which includes a form for calculating the amount of tip using the amount of the bill without tip and the tip percentage.
* The bill subtotal should be a text input to allow any value.
* The tip percentage should use radio buttons for three choices: 10%, 15%, and 20%. IMPORTANT: You MUST use a PHP loop to output the three radio buttons.
GIF created with [LiceCap](http://www.cockos.com/licecap/).

* Submitting the form will initiate form processing using PHP. It should:
* Set reasonable default values.
* Confirm the presence and format of submitted values. The bill subtotal should be present and greater than 0. The percentage should be present and greater than 0.
* If all values are valid, calculate the amount of the tip and the total bill when the tip is included.
## Notes

* After PHP processes the form, the form should be re-displayed with:
* Form fields pre-populated with the submitted values and selections.
* Indicate any form errors which need to be fixed.
* If all values were valid, display the amount of the tip and the total bill when the tip is included in a box below the form. Be sure to format the values properly as currency. This result box should not display the first time the page loads (only after a form is submitted).
The only part that was challenging was the error handling.

* Use CSS to add design to make your page look good.


**An example of the finished product with required features complete:**

<img src='http://i.imgur.com/I5WIJ3S.gif' title='tip calcculator - required' width='' alt='tip calcculator - required' />

### 3. Submit your code for review

Once you've completed the Tip Calculator application, please [push your app via Github](https://help.github.com/articles/create-a-repo). Also be sure to **include a README** containing a GIF walkthrough using [LiceCap](http://www.cockos.com/licecap/) of the app demonstrating how it works with required user stories completed. Use [this README template](https://raw.githubusercontent.com/ACM-SNU/php-task/master/README-template.md).

After you have **completed all required user stories and added a README as described above** then you are ready to notify us that you are ready for a pre-work review. You can either mail us at [email protected] or send a pull request to this repository.

**Note:** All project code repos are pushed to github. If needed, review how to push your apps to github with [this handy tutorial](https://help.github.com/articles/create-a-repo). You should add a [.gitignore](https://raw.githubusercontent.com/github/gitignore/master/Objective-C.gitignore) to your project as well to **avoid storing compiled and local files in git**.

### Submission Checklist

Please **review the following checklist** to ensure your submission is valid:
1. Did you successfully **push your code to github**? Can you see the code on GitHub?
2. Did you **add a README** which includes a **GIF walkthrough** of the app's functionality?
3. Did you **use our [README template](https://raw.githubusercontent.com/ACM-SNU/php-task/master/README-template.md)** for your README?
4. Does your **GIF render directly in your README?** When using Imgur, you can right-click on the gif and choose "Copy Image Address" to get the correct address. Make sure the address has a `.gif` extension. If you end up with a url that has a `.gifv` extension, removing the `v` and changing this to `.gif` will ensure the gif renders on GitHub.

Congratulations on completing the required portion of the pre-work! The remaining steps are optional, but **completing them will significantly improve your skills**.

### 4. Optional: Add support for custom tip percentage

* After the three percentage radio buttons, add a fourth radio button labeled "Custom". Include a text input to allow users to enter a custom tip percentage value (such as "18.5").

* In the PHP processing, use the custom tip percentage whenever "Custom" has been selected. Be sure to provide good default values and to correctly re-display all the submitted values when the result is shown.


### 5. Optional: Add support for splitting the tip and total

* Add a new text input which will allow users to split the tip and total bill between any number of people.

* The split number should default to 1 and should not work for 0 or negative numbers.

* Display both the split tip and the split total.


### 6. Optional: Extend your app, improve UI, add features

The sky's the limit on ways you can improve your code. Some ideas include:
* improve the design
* add JavaScript or Ajax (but not to replace the PHP)
* define custom functions to better organize the code
* enhance the error messages
* use locale specific currency
* add a currency thousands separator
* store the last submission in a cookie or the session

## An example of the finished product with required features complete:

<img src='http://i.imgur.com/0ifXl8f.gif' title='tip calculator - optionals' width='' alt='tip calculator - optionals' />
8 changes: 8 additions & 0 deletions handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if(isset($_POST["inter"])){
$last = $_POST["inter"];
}else{
$last = 0;
}
?>
Binary file added img.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions site.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>

<center>
<?php

require "view.php"; // Refers to the main site. //

$tip = (float)$_POST["bill"]*$_POST["inter"]; // Calculates the tip using bill * percent/100 formula. //
$total = (float)$_POST["bill"]+(float)$tip; // Calculates total after adding tip to bill. //
$flag = 0;
if ($tip > 0){
// If tip is greater than 0, then only we should print our result else not. //?>
<?php
echo "<div>Tip: $".$tip."<br> Total: $".$total."</div>";
?>
<?php
}else{
echo "<div>Either the tip is zero or the input is not valid.</div>";
}

?>

</center>

</body>
</html>
23 changes: 23 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pr {
color: red;
}

parent {
color:red;
border-style: solid;
border-width: medium;
}

div {
width: 300px;
border: 5px solid green;
padding: 25px;
margin: 25px;
}

div1 {
width: 300px;
border: 5px solid black;
padding: 25px;
margin: 25px;
}
45 changes: 45 additions & 0 deletions view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!doctype html>
<head>
<title> TIP CALCULATOR </title>
<link rel="stylesheet" href="style.css">
</head>

<body bgcolor="yellow">

<center>

<h2> <parent>Tip Calculator </parent></h2>


<form action = 'site.php' method = 'post'>
<pr>BILL $: <input type="text" name="bill" value="<?php echo isset($_POST['bill']) ? $_POST['bill'] : '1000' ?>"><br>

<?php
$data = [
0.1,
0.15,
0.2
];
?>

<br>
<u>Tip percentage:</u> <br>
<br>

<?php foreach($data as $val){ ?>
<input type='radio' name='inter' value="<?php echo $val;?>" <?php require 'handler.php'; if($val == $last) echo "checked";?>> <?php echo $val*100;?> %;
<?php } ?>

<br>

<br>
<input type="submit">
</pr>
</form>


</center>


</body>
</html>