I’m using Kirby Uniform instead of building a form by hand following this. Say I want to dynamically add a set of forms from the panel:
in template.php I loop over a Kirby Builder object and have printed only the selected forms from a list of available forms, but when using Kirby Uniform it seems you have to define upfront the kind of forms you want to use on the page.
My doubt is: does it make sense to define all available forms listed in the panel also in controller.php, or is better / is there a way to loop over an object also in Kirby Uniform’s controller.php?
If it’s the latter, how would you do that?
Something like this?
$form = array();
foreach($_POST as $key => $value) {
// tell not to pick honeypot values up
if ($key != 'submit' && $key != 'website') {
$form[$key] = esc($value);
}
};
EDIT
seeing this
ofc reading from the docs, if you use an empty array then Uniform does not save that data as required.
Probably looking elsewhere, to the point of reimplementing this solution.
Though I feel this would be possible also with the Uniform plugin?
Was your illegal offset error in the panel or on the site itself? I have had issues with the most recent kirby version and the builder plugin, illegal offset included. Try down grading Kirby to 2.5.3 or 2.5.4. Hopefully the builder plugin will be updated soon.
I couldn’t access $page in the same way you do in a front side template in the panel either. Try:
Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key.
– SO
So $section->_fieldset() might not return a string as I expected. See what the return value actually is and use something else. Since you already use the builder object to build the form in the template you must take the same property than you use for the name attributes of the form fields.
i think u need to give that a little more… as i said, my PHP is pretty green, but with that your basically accessing $site and since theres no builder field on your site options page, the array is getting nothing. I think you need to be more specific about where the data is your are trying to populate the array is.
This was inside one of my builder snippets, and the builder print contained a drop down (teasercontent) of all pages so i could create a teaser hero panel just by picking a page. youll probably wont some way similar to feed the page through that has the data you want to use.
Also, i dont know if you are aware, but controllers only work on the page that controller belongs too. To have it work on any page, you need to rename the controller to site.php. For example, i have a newsletter signup form on every page. Rather then put the Uniform controller code in duplicated controllers, you can put in a controller called site.php. This might be contributing to your problem.
which gives me an objectarray (?), and once I use it inside the Uniform controllers.php loop I get the same Offset Illegal Type error as in the beginning.
This makes me think the problem is not using $page or $page->site()-> etc after all?
I am also getting back to PHP after a while and am not very sharp lately… will keep pocking at it.
again… flakey PHP knowledge…but its a number isn’t it, not a string, and your treating it as a string? Shouldnt you first check the value is string or a number then treat it appropriately? If you changed that number field to a text field, i bet you get a value.
What does var_dump() tell you?
strval($value); converts an int to a string. Or this.