I am doing some practicing with OOP in PHP, and am having issues with submitting form data involving subclasses.
What I am trying to do: submit form data based on the type of product it is (generic, tool, or electronic). My concern comes from not being able to submit a form that can differentiate between the different product types.
Here's the Product Class (the base class):
<?php
require_once('connectvars.php');
// Base class!!
class Product {
// Inheritable properties
protected $title;
protected $description;
protected $price;
// Getters
public function getTitle() {
return $this->title;
}
public function getDescription() {
return $this->description;
}
public function getPrice() {
return $this->price;
}
// Setters
public function setTitle($title) {
$this->title = $title;
}
public function setDescription($description) {
$this->description = $description;
}
public function setPrice($price) {
$this->price = $price;
}
public function insertProduct() {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME);
$query = "INSERT INTO addedProducts VALUES (0,'$this->title', '$this->description', '$this->price', '', '', '')";
mysqli_query($dbc, $query)
or die("Error adding to database");
mysqli_close($dbc);
}
}
?>
Here's a subclass I made called Tools:
<?php
require_once('connectvars.php');
require_once('Product.php');
class Tools extends Product {
// Defined properties specific to Tools class
private $shipper;
private $weight;
// Getters
public function getShipper() {
return $this->shipper;
}
public function getWeight() {
return $this->weight;
}
// Setters
public function setShipper($shipper) {
$this->shipper = $shipper;
}
public function setWeight($weight) {
$this->weight = $weight;
}
public function insertTool() {
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME);
$query = "INSERT INTO addedProducts VALUES (0,'$this->title', '$this->description', '$this->price', '$this->shipper', '$this->weight', '')";
mysqli_query($dbc, $query)
or die("Error adding to database");
mysqli_close($dbc);
}
}
?>
This is where I am running into problems:
<!DOCTYPE html>
<html>
<head>
<title>Product Entry</title>
</head>
<body>
<select name="prodType" id="prodType">
<option value="" selected="selected">Select...</option>
<option value="general">General</option>
<option value="tools">Tools</option>
<option value="electronics">Electronics</option>
</select>
<br/><br/>
<?php
//require_once('connectvars.php');
require_once('Product.php');
require_once('Electronics.php');
require_once('Tools.php');
$product = new Product();
$tool = new Tools();
$electronic = new Electronics();
if (isset($_POST['submit']) && (isset($_POST['prodType']) == 'general')) {
$product_form = false;
$product->setTitle($_POST['title']);
$product->setDescription($_POST['description']);
$product->setPrice($_POST['price']);
$product->insertProduct();
/*$tool->setTitle($_POST['title']);
$tool->setDescription($_POST['description']);
$tool->setPrice($_POST['price']);
$tool->setShipper($_POST['shipper']);
$tool->setWeight($_POST['weight']);
if (!empty($tool->getTitle()) && !empty($tool->getDescription()) && is_numeric($tool->getPrice()) && !empty($tool->getShipper()) && !empty($tool- >getWeight())) {
echo 'Tool submitted <br/>';
//echo 'Go Back';
$tool->insertTool();
}
} else {
$product_form = true;
}
if ($product_form) {
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<label for="title"><strong>Product Title</strong></label>
<br/>
<input type="text" id="title" name="title" value="<?php echo $product->getTitle();?>"/>
<br/><br/>
<label for="description"><strong>Description</strong></label>
<br/>
<input type="text" id="description" name="description" value="<?php echo $product->getDescription();?>"/>
<br/><br/>
<label for="price"><strong>Price</strong></label>
<br/>
<input type="text" id="price" name="price" value="<?php echo $product->getPrice();?>"/>
<br/><br/>
<!--For Tools -->
<label for="shipper"><strong>Shipper Info</strong></label>
<br/>
<select name="shipper" id="shipper">
<option value="none" selected="selected">--</option>
<option value="usps">USPS</option>
<option value="fedex">FedEx</option>
<option value="ups">UPS</option>
</select>
<br/><br/>
<label for="weight"><strong>Weight</strong></label>
<br/>
<input type="text" id="weight" name="weight" value="<?php echo $tool->getWeight();?>"/>
<br/><br/>
<!--For Electronics -->
<label for="recyclable"><strong>Recyclable?</strong></label>
<br/>
<select name="recyclable" id="recyclable">
<option value="none" selected="selected">--</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<br/><br/>
<input type="submit" id="submit" name="submit" value="Submit Product"/>
</form>
<?php
}
?>
</body>
</html>
I'm sure there's a fairly straightforward solution, but I'm no longer thinking about this correctly anymore -_-. Any suggestions?
I would do the following:
Move all of your calculations to the top of the file.
Move your prodType into the form.
I am displaying the form always. In 1 instance it is to edit, in another it is to create. But you will want to add a hidden input for the "product_id"
Like this:
<?php
require_once('Product.php');
require_once('Electronics.php');
require_once('Tools.php');
$product = new Product();
$tool = new Tools();
$electronic = new Electronics();
if (isset($_POST['submit'])){
$prodType = $_POST['prodType'];
if($prodType == 'general') {
$product_form = false;
$product->setTitle($_POST['title']);
$product->setDescription($_POST['description']);
$product->setPrice($_POST['price']);
$product->insertProduct();
} else if($prodType == 'tools') {
} else if ($prodType == 'elecronics') {
} else {
// echo this message in the form.
$msg = 'Invalid product type';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Product Entry</title>
</head>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<select name="prodType" id="prodType">
<option value="" selected="selected">Select...</option>
<option value="general">General</option>
<option value="tools">Tools</option>
<option value="electronics">Electronics</option>
</select>
<br/><br/>
<label for="title"><strong>Product Title</strong></label>
<br/>
<input type="text" id="title" name="title" value="<?php echo $product->getTitle();?>"/>
<br/><br/>
<label for="description"><strong>Description</strong></label>
<br/>
<input type="text" id="description" name="description" value="<?php echo $product->getDescription();?>"/>
<br/><br/>
<label for="price"><strong>Price</strong></label>
<br/>
<input type="text" id="price" name="price" value="<?php echo $product->getPrice();?>"/>
<br/><br/>
<!--For Tools -->
<label for="shipper"><strong>Shipper Info</strong></label>
<br/>
<select name="shipper" id="shipper">
<option value="none" selected="selected">--</option>
<option value="usps">USPS</option>
<option value="fedex">FedEx</option>
<option value="ups">UPS</option>
</select>
<br/><br/>
<label for="weight"><strong>Weight</strong></label>
<br/>
<input type="text" id="weight" name="weight" value="<?php echo $tool->getWeight();?>"/>
<br/><br/>
<!--For Electronics -->
<label for="recyclable"><strong>Recyclable?</strong></label>
<br/>
<select name="recyclable" id="recyclable">
<option value="none" selected="selected">--</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<br/><br/>
<input type="submit" id="submit" name="submit" value="Submit Product"/>
</form>
</body>
</html>
Note: You should use and learn composer. It is a must have tool to autoload your class files.
Related
I don't know how to add a double record to db.
I have form with double same row content.
I would like to add a dynamic line in the next step using js but at this point I used double html to validate it.
<form class="formAddCoupon" action="/?dashboard=coupon" method="post">
<div class="windowEvents">
<div class="row">
<input type="text" class="teamInput" name="team1">
<input type="text" class="teamInput" name="team2">
<select name="score" id="selectOptions">
<option value="Liczba bramek">Liczba bramek</option>
<option value="Liczba rzutów rożnych">
Liczba rzutów rożnych</option>
<option value="Ilość kartek">Liczba kartek</option>
<option value="Wygrana drużyny">Wygrana drużyny</option>
<option value="Wygrana drużyny lub połowy">
Wygrana drużyny lub połowy</option>
<option value="Wygrana połowy">Wygrana jednej z połów</option>
<option value="Hendicap">Hendicap</option>
<option value="Ilość punktów">Liczba punktów</option>
</select>
<input type="text" class="scoreInput" name="type_score">
</div>
<div class="row">
<input type="text" class="teamInput" name="team1">
<input type="text" class="teamInput" name="team2">
<select name="score" id="selectOptions">
<option value="Liczba bramek">Liczba bramek</option>
<option value="Liczba rzutów rożnych">
Liczba rzutów rożnych</option>
<option value="Ilość kartek">Liczba kartek</option>
<option value="Wygrana drużyny">Wygrana drużyny</option>
<option value="Wygrana drużyny lub połowy">
Wygrana drużyny lub połowy</option>
<option value="Wygrana połowy">Wygrana jednej z połów</option>
<option value="Hendicap">Hendicap</option>
<option value="Ilość punktów">Liczba punktów</option>
</select>
<input type="text" class="scoreInput" name="type_score">
</div>
</div>
<div class="valueAmountRow">
<input
type="number"
name="bid_amount"
id="bid_amount"
placeholder="Stawka"
min="0"
step="any"
>
<input
type="number"
name="winner_amount"
id="winner_amount"
placeholder="Wygrana"
min="0"
step="any"
>
<input type="submit" value="Dodaj">
</div>
</form>
Controller.php:
$data = $this->getRequestPost();
If(!empty($data)) {
$couponData = [
'bid_amount' => $data['bid_amount'],
'winner_amount' => $data['winner_amount'],
'team1' => $data['team1'],
'team2' => $data['team2'],
'score' => $data['score'],
'type_score' => $data['type_score'],
];
$this->db->createCoupon($couponData);
}
Database.php
public function createCoupon(array $data)
{
try {
$this->createNewCoupon($data);
} catch(Throwable $e) {
dump($e);
throw new StorageException('Nie udało się wysłać kuponu', 400, $e);
}
}
private function createNewCoupon($data): void
{
$nr_coupon = trim($this->connection->quote($this->checkIssetCode()));
$created = $this->connection->quote(date('Y-m-d H:i:s'));
$bid_amount = trim($this->connection->quote($data['bid_amount']));
$winner_amount = trim($this->connection->quote($data['winner_amount']));
$team1 = trim($this->connection->quote($data['team1']));
$team2 = trim($this->connection->quote($data['team2']));
$score = trim($this->connection->quote($data['score']));
$typeScore = trim($this->connection->quote($data['type_score']));
$insertNumberCoupon = "INSERT INTO
coupon_number(
nr_coupon,
created,
bid_amount,
winner_amount
)
VALUES(
$nr_coupon,
$created,
$bid_amount,
$winner_amount
)";
$sql_create_number_coupon = $this->connection->prepare($insertNumberCoupon);
if($sql_create_number_coupon)
{
$sql_create_number_coupon->execute();
$id = (int) $this->connection->lastInsertId();
$addEvent = "INSERT INTO
events_at_coupon(
number_id_coupon,
team1,
team2,
score,
type_score
)
VALUES($id,$team1,$team2,$score,$typeScore)";
$sql_add_event_to_table = $this->connection->prepare($addEvent);
if($sql_add_event_to_table)
{
$sql_add_event_to_table->execute();
}
}
}
When i send a form only one record is added to database.
I know why, but what do i have to do to get a double record ?
It shows me this error: Column 'zeme_idZeme' cannot be null
I thought <select name="zeme_IdZeme"> this would be sufficient, but I was wrong about it.
View:
<body>
<div class="main-block">
<h1>Film</h1>
<form method="post" action="<?php echo base_url('/form') ?>">
<div class="info">
<input type="text" name="cesky_nazev" required="vyžadováno" placeholder="Český název filmu">
<input type="text" name="originalni_nazev" required="vyžadováno" placeholder="Původní název filmu">
<input type="number" name="delka_filmu" required="vyžadováno" placeholder="Délka filmu">
<input type="text" name="typ_filmu" required="vyžadováno" placeholder="Typ filmu">
<select name="zeme_IdZeme">
<option disabled selected>Země</option>
<?php
$query = $db->query("SELECT * FROM zeme");
foreach ($query->getResult() as $row)
{ ?>
<option value="5"> <?php echo $row->nazev;}?></option>
</select>
</div>
<button type="submit" class="button">Odeslat</button>
</form>
</div>
</body>
Controller:
public function form() {
$data = [ 'cesky_nazev' =>$this->request->getVar('cesky_nazev'),
'originalni_nazev' =>$this->request->getVar('originalni_nazev'),
'delka_filmu' =>$this->request->getVar('delka_filmu'),
'typ_filmu' =>$this->request->getVar('typ_filmu'),
'zeme_idZeme' =>$this->request->getVar('zeme_idZeme'),
'zanrFilmu_idZanrFilmu' =>$this->request->getVar('zanrFilmu_idZanrFilmu'),
'promitani_idPromitani' =>$this->request->getVar('promitani_idPromitani'),
'jazyky_idJazyky' =>$this->request->getVar('jazyky_idJazyky') ];
/*
$db = \Config \Database::connect();
$builder = $db->table('film');
$builder->insert($data); */
$model = new Film_formular();
if ($model->insert($data))
{
echo view('templates/header');
?><style>.center {text-align: center;color: red;}</style><?php
echo "<h3 class='center'>Úspěšně přidáno</h3>";
echo view('film_formular');
echo view('templates/footer');
}
else
{
echo "nepřidáno";
}
}
model:
<?php namespace App\Models;
use CodeIgniter\Model;
class Film_formular extends Model
{
protected $table = 'film';
protected $allowedFields = ['cesky_nazev', 'originalni_nazev', 'delka_filmu', 'typ_filmu', 'zeme_idZeme', 'zanrFilmu_idZanrFilmu','promitani_idPromitani','jazyky_idJazyky'];
}
The option close tag aren't inside foreach. Move the bracket after option close tag
<select name="zeme_IdZeme">
<option disabled selected>Země</option>
<?php
$query = $db->query("SELECT * FROM zeme");
foreach ($query->getResult() as $row)
{
?>
<option value="5"> <?php echo $row->nazev;?></option>
<?php
}
?> </select>
If the combobox select the Archers the browser will echo Correct but if the combobox will not select the Archers the browser will echo, i want to know if my syntax is wrong.
Wrong. Error: Undefined index text_hname.
Here's the structure:
<form action="server.php" method="POST">
<img src="images/logo.png" class="logo">
<div class="container">
<h1>Account Details</h1>
<br>
<label class="username">Username</label>
<input type="text" name="text_username" class="text_user" placeholder="Enter username">
<label class="password">Password</label>
<input type="text" name="text_password" class="text_pass" placeholder="Enter password">
<label class="email">Email</label>
<input type="text" name="text_email" class="text_email" placeholder="Enter email">
<label class="cname">Character Name</label>
<input type="text" name="text_cname" class="text_cname" placeholder="Enter Character Name">
<label class="character">Select Character</label>
<select class="names" name="text_hname">
<option>Archer</option>
<option>Barbarian</option>
<option>Balloon</option>
<option>Witch</option>
<option>Spirit</option>
<option>Hog Rider</option>
<option>Minion</option>
</select>
<img src="images/">
<br>
<input type="submit" class="submit" name="submit">
</div>
</form>
//option
$hero = $_POST['text_hname'];
if (isset($_POST['text_hname'])) {
if ($hero == 'Archers') {
echo "Correct";
} else {
echo "wrong";
}
}
The problem is that if you're trying to assign $hero before you've checked if text_hname is set, it might not be defined.
Suggested refactor:
if (isset($_POST['text_hname'])) {
$hero = $_POST['text_hname'];
if ($hero == 'Archers') {
echo "Correct";
}
else
{
echo "wrong";
}
}
//Your select in form needs values. Same values that you are going to compare.
<select class="names" name="text_hname">
<option value="Archer">Archer</option>
<option value="Barbarian">Barbarian</option>
<option value="Balloon">Balloon</option>
<option value="Witch">Witch</option>
<option value="Spirit">Spirit</option>
<option value="HogRider">Hog Rider</option>
<option value="Minion">Minion</option>
</select>
//Php code
if (isset($_POST['text_hname'])) {
$hero = $_POST['text_hname'];
if ($hero == 'Archer') { //Its Archer, not Archers
echo "Correct";
}
else
{
echo "wrong";
}
}
$_POST['text_hname'] will return the selected option value , not option name .
Modify your select like this:
<select class="names" name="text_hname">
<option value="Archer">Archer</option>
<option value="Barbarian">Barbarian</option>
<option value="Balloon">Balloon</option>
<option value="Witch">Witch</option>
<option value="Spirit">Spirit</option>
<option value="Hog_Rider">Hog Rider</option>
<option value="Minion">Minion</option>
</select>
and server.php page
if (isset($_POST['text_hname'])) {
$hero = trim($_POST['text_hname']); //** to remove any whitespace
if ($hero == 'Archer') {
echo "Correct";
} else {
echo "wrong";
}
}
EDIT : it might be because your $_POST['text_hname'] has whitespace. Try trim() on $_POST['text_hname']
Hope it's helpful.
SO I inputted values through a datetime jquery plugin and now i am inserting the values in my database through mysqli php extension .
But the problem is it is not inserting.It always goes into the else condition. I have my form in scheduler.php page from there i am sending values to allforms.php from there i am calling add method of class Scheduler which resides in user.php page
allforms.php page
$operation = $_POST['operation'];
if($operation == 'add'){
$request = getSchedule();
$scheduler = new Scheduler($request['title'],$request['urgency'],$request['meeting'],$request['minfo'],$request['snooze'],$request['textbox'],$request['datetime']);
$result = $scheduler->add();
echo $result;
}
function getSchedule(){
$request = [];
$request['title'] = isset($_POST['title']);
$request['urgency'] = isset($_POST['urgency'])?$_POST['urgency']:'';
$request['meeting'] = isset($_POST['meeting'])?$_POST['meeting']:'';
$request['minfo'] = isset($_POST['minfo'])?$_POST['minfo']:'';
$request['snooze'] = isset($_POST['snooze'])?$_POST['snooze']:'';
$request['textbox'] = isset($_POST['textbox'])?$_POST['textbox']:'';
$request['datetime'] = isset($_POST['datetime'])?strtotime($_POST['datetime']):'';
$request['datetime'] = date("Y-m-d",$request['datetime']);
return $request;
}
scheduler.php Page
class Scheduler {
public $title;
public $urgency;
public $meeting;
public $minfo;
public $snooze;
public $textbox;
public $datetime;
public function __construct($title,$urgency,$meeting,$minfo,$snooze,$textbox,$datetime){
$this->title =$title;
$this->urgency = $urgency;
$this->meeting = $meeting;
$this->minfo =$minfo;
$this->snooze = $snooze;
$this->textbox = $textbox;
$this->datetime = $datetime;
$connection = new Connection();
$this->connect = $connection->connect();
}
public function add(){
$sql = "INSERT INTO
Meeting (title, urgency, meeting, minfo, snooze, textbox, datetime)
VALUES ('{$this->title}', '{$this->urgency}', '{$this->meeting}', '{$this->minfo}','{$this->snooze}','{$this->textbox}','{$this->datetime}')";
$result = $this->connect->query($sql);
if($result)
{
return $this->title ." has been registered ";
}else {
return "Some error occured and we couldn't add the event";
}
}
}
scheduler.php Page
<form class="form-group" method="POST" action="allforms.php" >
<div>
<label><b>Title</b></label>
<input type="text" placeholder="Enter your title here" name="title" >
</div>
<div>
<label><b>Urgency Level</b></label>
<select name="urgency" class="textbox" >
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="Critical">Critical</option>
</select>
</div>
<div>
<label><b>Meeting Type</b></label>
<select name="meeting" class="textbox">
<option value="Telephonic">Telephonic</option>
<option value="Offline">Offline</option>
<option value="Online">Online</option>
</select>
</div>
<div>
<label><b>Meeting Info</b></label>
<input type="text" name="minfo" placeholder="Enter location name , number or skype id ,etc.">
</div>
<div>
<label><b>Snooze</b></label>
<input type="number" placeholder="Enter Snooze time in minutes" name="snooze" class="textbox">
</div>
<div>
<label><b>Description</b></label>
<textarea name="textbox" class="textbox"></textarea>
</div>
<div class="form-group">
<label><b>Date/Time of the meeting</b></label>
<input type='text' id="datetimepickr" class="form-control" name="datetime">
</div>
<input type="hidden" name="operation" value="add">
<button type="submit" name="add">Submit</button>
</form>
change your datetime format,
function getSchedule(){
$request = [];
$request['title'] = isset($_POST['title']);
$request['urgency'] = isset($_POST['urgency'])?$_POST['urgency']:'';
$request['meeting'] = isset($_POST['meeting'])?$_POST['meeting']:'';
$request['minfo'] = isset($_POST['minfo'])?$_POST['minfo']:'';
$request['snooze'] = isset($_POST['snooze'])?$_POST['snooze']:'';
$request['textbox'] = isset($_POST['textbox'])?$_POST['textbox']:'';
$request['datetime'] = isset($_POST['datetime'])?strtotime($_POST['datetime']):'';
$request['datetime'] = date("Y-m-d H:i",$request['datetime']);
return $request;
}
I'm trying to build a manual form on a Wordpress page.
My goal is to create a dropdown menu of all the users with a fixed role (in my case "athlete") and register single users in some sport events.
My code:
<form name="team_captain" method="POST" >
Carnival Name: <input type="text" id="carnival_name" name="carnival_name" />
<input type="submit" name="submit_carnival" value="Create Carnival"/><br />
Event Name: <select name="event_name">
<option value="Ironman Race">Ironman Race</option>
<option value="Board Race">Board Race</option>
<option value="Ski Race">Ski Race</option>
<option value="Surf Race">Surf Race</option>
</select><br />
Athlete Name:
<select name="athlete_name">[insert_php] echo getUsersByRole('athlete','athlete-selector'); [/insert_php]</select><br />
Age Group: <select name="age_group">
<option value="Under 15">Under 15</option>
<option value="Under 17">Under 17</option>
<option value="Under 19">Under 19</option>
<option value="Open">Open</option>
</select><br />
Sex: <input type="radio" name="athlete_sex" value="Male">Male <input type="radio" name="athlete_sex" value="Female">Female<br />
<input type="submit" value="Insert Race"/>
</form>
[insert_php]
if(isset($_POST['submit_carnival'])) {
$carnival_name = $_POST['carnival_name'];
echo "Registrations for ".$carnival_name;
}
elseif(isset($_POST['submit'])) {
$event_name = $_POST["event_name"];
$athlete_sex = $_POST["athlete_sex"];
$age_group = $_POST["age_group"];
$athlete_name = $_POST["athlete_name"];
echo $event_name;
echo $age_group;
echo $athlete_sex;
echo $athtlete_name;
}
[/insert_php]
At this point I can display the name of the carnival, but I can't display the instances of the athletes. And the dropdown list of the athletes doesn't work.
This is the function:
function getUsersByRole($role,$name,$selected = '',$extra = '') {
global $wpdb;
$wp_user_search = new WP_User_Query(array("role"=> $role));
$role_data = $wp_user_search->get_results();
foreach($role_data as $item){
$role_data_ids[] = $item->ID;
}
$ids = implode(',', $role_data_ids);
$r = $wpdb->get_results("SELECT * from ".$wpdb->prefix . "users where id IN(".$ids .")", ARRAY_A);
$content .='<select name="'.$name.'" id="'.$name.'" '.$extra.'>';
if($selected == ''){
$content .='<option value="" selected="selected">Choose a user</option>';
}else{
$r_user = $wpdb->get_results("SELECT * from ".$wpdb->prefix . "users where ID = ".$selected."", ARRAY_A);
$content .='<option value="'.$selected.'" selected="selected">'.stripslashes($r_user[0]['display_name']).'</option>';
}
for($i=0; $i<count($r); $i++){
$content .='<option value="'.$r[$i]['ID'].'">'.stripslashes($r[$i]['display_name']).'</option>';
}
$content .='</select>';
return $content;
}
Because you're looking for a $_POST["submit"], you'll have to have an input with the name attribute equal to submit. In your case replace this:
<input type="submit" value="Insert Race"/>
with this:
<input type="submit" name="submit" value="Insert Race"/>
Your getUsersByRole() function is already including the "select" tag, so replace this line:
<select name="athlete_name">[insert_php] echo getUsersByRole('athlete','athlete-selector'); [/insert_php]</select><br />
with this, notice that I changed "athlete-selector" to "athlete_name":
[insert_php] echo getUsersByRole('athlete','athlete_name'); [/insert_php]<br />
With those two changes, things should be working, though I haven't studied your getUsersByRole() function intensively, so there could be a bug in there. Let me know in a comment below if this works for you or not.