best way to pass form values
- jdan1131x
- Member | 41
Nette always has interesting ways to do things
that i dont know yet, so thought i would ask..
I know i can pass form values from step1presenter
to step2 presenter with:
A>
$this->getHttpRequest()->getPost();
code above in step 2 constructor…
or
B>
public function __construct(array $data) {
...
above code in step 2…
or
C>
/** @persistent */
public array $values;
$values = $form->values;
code above in step 1 and then capture with A> or B> above
or (i think…)
D>
{var $formvals = $form->values}
<div class="col-xs-12 col-md-4 pull-right" n:snippet="box1">
<a class="ajax btn btn-success btn-sm" n:href="{link step2:, data => $formvals}">Next Step2</a>
</div>
But given I dont want to store the data in db or file until step 4 or
5…
I think Step A and C are simplest way. But Step D and B seem good too.
or maybe something even more optimal is available? I really want to
standardize
how i pass data from presenter to presenter…
thanks for any input…
James
Last edited by jdan1131x (2021-05-01 19:17)
- jdan1131x
- Member | 41
thanks vm,
its too early in the dev cycle for nice forms like you mention.
but eventually…
step 1 form is simple and is working fine…
Class LessonOneFormFactory {
public function create(): Form {
$form = new Form();
$form->setMethod('GET');
$items = [
'simple' => 'simple',
'moderate' => 'moderate','advanced' => 'advanced','smart' => 'smart'
];
$form->addRadioList('type','Structure',$items)
->setHtmlAttribute('data-nette-compact');
$form->addCheckbox('userpref');
$form->addCheckbox('updatepref');
$form->addHidden('manager');
$form->addHidden('location');
$form->addHidden('docguid');
$form->addSubmit('send');
$form->addSubmit('clear');
return $form;
}
i am only working on path 1 (simple option) then step two in this path
will
query user for presentation method (upload or create simple html), then …
put into a distribution queue, then deliver via X.
moderate/advanced/smart paths 2–4 will require more…
as you can see in the form, i plan to let them store their selections
in their preferences too…
Thanks
James
- dsar
- Backer | 53
its too early in the dev cycle for nice forms like you mention.
In my opinion your multi-step form could be done with just one form, but look at this:
- jdan1131x
- Member | 41
Hey Dsar,
yes, thats very nice. agreed. will give it a try after i
understand the less elegant way…
I also like this piece:
/** @var Wizard @inject */
public $wizard;
as it will help me simplify my constructors a lot…
thanks again, you confirmed what i thought, that
there is another nice way…i didnt see that package in
componnette…
regards,
James
- jdan1131x
- Member | 41
i cannot seem to pass a simple query to a presenter constructor
i setup TestingPresenter as follows
use Nette;
class TestingPresenter extends Nette\Application\UI\Presenter {
public $data;
public function __constructor(string $data="") {
$this->data = $data;
}
public function renderDefault () {
$this->template->data = $this->data;
}
}
i set up the default.latte for Testing:
{block content}
<H3>{$user->getIdentity()->name}</H3>
<h4>{$data}</h4>
{/block}
the latte prints only my name, and not the $data string.
I tried these links in another Presenter with out success
$nexturl = $this->link('Testing:', ['data' => 'test']);
$this->template->nexturl = $nexturl;
and
<div >click <a href="{$nexturl}">Here</a></div>
and
<a class="test" href="{link {$next}: data => 'test' }">
with the code being:
protected string $next = "Testing";
i can see this → mydomain/testing/?data=test in the browser but
the word “test” is not being displayed in the Testing template.
I am sorry to ask for help on something seems so simple,
but have tried many diff ways…no success
James
- jdan1131x
- Member | 41
well, solved it. went jogging
came back, decided the post data was prob
going to renderDefault(), not __constructor(),
so did this:
public function renderDefault (string $data="") {
$this->template->data = $data;
}
and all is working fine. erased constructor. now i can
move on to walking the dog :-)
thanks much always, nette is awesome. a little
like climbing K2, at first :-)
James
- dkorpar
- Member | 135
You can't pass post variables to presenter constructor, it's wrong on many different levels…
Looks to me like you're missing some basic DI knowledge, see here: https://doc.nette.org/…introduction
- jdan1131x
- Member | 41
thanks very much, yes i am still unlearning my old skills where i would
instantiate objects inside classes
and pass all sorts of vars to the constructor…
i did find it passes arrays to renderDefault() …
i will learn… just have to practice, read,code,rinse and repeat.
regards,
James
- LilliBoisse
- Member | 1
I am agree with your answer my problem is solved. I am very happy 👍
Have a nice day to all the members 😇