Output Multiple Uniform Forms on the same page. (not Ajax)

Hi Kirby - Fellaz!

I have a short question: I’m trying to place more than just one form (multiple forms) on the same page but can’t find a good example how this should be done. Can you help me out? I’ve read the comments on the Uniform Blog Page and the Forum but could not find a good Code example.

Something like a Newsletter Subscription on the Sidebar and a Contact Form in the Footer area.

Many thanx!!!


ps. Asked the same question in the Uniform Blog. No answer yet…

You can simply call uniform() multiple times in the controller. Make sure every call has a unique ID as the first argument. Each form gets it’s own variable like this:

$form1 = uniform('form1', ...);
$form2 = uniform('form2', ...);

You can do this in a loop, too. In the template you only have to choose which variable you take for which form ($form1, $form2 etc.).

Hi mzur!

Thanx for your help!
That is exactly what I tried already.

…but I get two errors:
Notice: Undefined variable: form1 in /Users/funkybrotha/Sites/kirby-master/site/snippets/form1.php on line 3
Fatal error: Call to a member function hasError() on null in /Users/funkybrotha/Sites/kirby-master/site/snippets/form1.php on line 3

This is my setup: (screenshot)


Many thanx!


If you want to use variables in the snippets, you have to pass them along like so:

<?php snippet('form1', ['form1' => $form1]) ?>
<?php snippet('form2', compact('form2')) ?>

Also, in this forum you can paste your code directly. No need for huge screenshots :wink:

OK… I just wanted to show you my nice Sublime Text Theme. :wink:

I tried to pass the Variables along… but I still get the same Errors. ;-(

Yeah! Now it works!!!
This line was missing in controllers/default.php

// pass the variables to the template
return compact(‘form1’,‘form2’);

mzur, thanx a lot for your help!!!