Dostat výsledek formuláře do Textarea v něm
- iDome89
- Člen | 27
Chtěl bych výsledek výpoctu hodnot zadaných v inputech, zobrazit v textArea, ale nevim absolutne jak, nevíte jak na to? v TextArea chci aby byl videt výsledek $total.
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette\Application\UI;
class HomepagePresenter extends UI\Presenter
{
/** @var Nette\Database\Context */
private $database;
public function __construct(\Nette\Database\Context $database)
{
$this->database = $database;
}
protected function createComponentCalculationForm(): UI\Form
{
$supplierList = $this->database->table("suppliers")->fetchPairs("id", "supp_name");
$form = new UI\Form;
$form->addSelect('supplier', 'Dodavatel:',$supplierList);
$form->addText('quantity', 'Ks')
->setRequired()
->setHtmlType('number');
$form->addText('price', 'Kč')
->setRequired()
->setHtmlType('number');
$form->addSubmit('calculate', 'Spočítat');
$form->onSuccess[] = [$this, 'calculatePrice'];
$form->addTextArea('result');
return $form;
}
public function calculatePrice(UI\Form $form, \stdClass $values){
$values=$form->getValues();
$price= $values->price;
$selectedSupp=$values->supplier;
$quantity=$values->quantity;
$modifier=$this->database->fetch('SELECT percentage FROM prices WHERE supplier_id = ? AND max >= ? AND min <= ?', $selectedSupp, $quantity, $quantity);
$total=$price + ($price / 100)* $modifier->percentage;
return dump($total);
}
}
?>