Comments (24)
I've just tested it with my template looking like this:
<?php snippet('header') ?>
<main class="main" role="main">
<?php snippet('form') ?>
</main>
<?php snippet('footer') ?>
And site/snippets/form.php
exactly containing the basic example code. It worked fine.
Could you copy & paste both template and snippet code and try again?
from kirby-uniform.
Thx @mzur I tested some variations yesterday myself and it worked. I think it's because of the way the data is passed through on the one-pager solution http://getkirby.com/docs/solutions/one-pager. I'm using that structure for an actual client project.
The main template (I'm only using one) looks like this:
<?php
snippet('header');
foreach($pages->visible() as $section) {
snippet($section->uid(), array('data' => $section));
}
snippet('footer');
The snippet itself is just the basic code as you published it.
Any clue on where I'm doing something wrong?
from kirby-uniform.
For me it even works with the one-pager template. Maybe you could provide a little more of your templates/snippets that don't work so I can reproduce the behaviour?
from kirby-uniform.
Weird ... I just tryed your updated code on a clean one-pager slate and it worked as well. Let my try later on with the page I'm working on. I don't want to mess with that code right now. I'll let you know if it worked.
from kirby-uniform.
I'm having the same problem. I think it may be related to the controller code? Where do you put it in a one-pager with a form in a snippet/snippet.php? If I put it in controllers/home.php (with templates/home.php being my main one-pager template) I get "Undefined variable: form" error. If I put it in controllers/snippet.php the form shows but no email is being sent.
from kirby-uniform.
@rik84 It should work if you put the controller code to controllers/home.php
(since controllers are for templates only, I understand) and then pass on the $form
variable to the snippet like this:
snippet($section->uid(), array('data' => $section, 'form' => $form));
And don't forget to export the $form
variable from the controller, otherwise it would always be undefined in the template.
from kirby-uniform.
I am experiencing a similar issue. I put my contact form in a snippet and used it in a template for a contact-us sup page and it worked without any issues. Now I've added the snippet to a section on the home page (I also added the home controller stuff) but the form doesn't work.
When I look at the form source I can see that the button has a token that was generated by $form->token()
so the controller must be working. However when I submit the form the page reloads, the form is empty and there is no success or error message.
I did discover that when I add /home to the end of the form action action="<?php echo $page->url()?>/home"
it actually works. However since I want to use the form as a snippet this is not great solution.
Is this a bug with kirby or with the uniform plugin?
from kirby-uniform.
@wtip I just implemented a form as a snippet on the home page and it works fine for me. Does $page->url()
return the correct URL of your home page? Is there a redirect or something from your site root to the home page?
from kirby-uniform.
$page->url()
does return the correct URL of the home page. Though the home page has two correct URLs. One being the bare domain example.com and the other being example.com/home I wonder if it has anything to do with my use of routes?
c::set('routes', array(
array(
'pattern' => 'tag/(:any)',
'action' => function($tag) {
$data = array('tag' => $tag);
site()->visit('articles');
return array('archive', $data);
}
),
array(
'pattern' => '(:num)/(:num)/(:num)',
'action' => function($year, $month, $day) {
if(($year > 0 && $year <= 9999)
&& ($month > 0 && $month <= 12)
&& ($day > 0 && $day <= 31)) {
$data = array('year' => $year,
'month' => $month,
'day' => $day);
return array('archive', $data);
} else {
go('error');
}
}
),
array(
'pattern' => '(:num)/(:num)',
'action' => function($year, $month) {
if(($year > 0 && $year <= 9999)
&& ($month > 0 && $month <= 12)) {
$data = array('year' => $year,
'month' => $month);
return array('archive', $data);
} else {
go('error');
}
}
),
array(
'pattern' => '(:num)',
'action' => function($year) {
if($year > 0 && $year <= 9999) {
$data = array('year' => $year);
return array('archive', $data);
} else {
go('error');
}
}
)
));
from kirby-uniform.
For now I am using this action="<?php echo url() ?>/<?php echo $page->slug() ?>
to get a form action url that works on any page.
from kirby-uniform.
Does it work if you disable the routing?
from kirby-uniform.
Could this be reopened? I'm having the same issue as @wtip, where the form suddenly stops working if I put it on the homepage. Following your example with <form action="<?php echo $page->url()?>" method="post">
does not work for me, but implementing @wtip last post, with action="<?php echo url() ?>/<?php echo $page->slug() ?>
does make it work.
I'm thinking this is because something makes the form break when we're not on the correct url? Meaning that /
is not treated equally as home
, even though that is my homepage c::set('home','home');
from kirby-uniform.
@BeSports Can you make a quick Kirby setup where the form fails in exactly the way you are describing? Then I can download it and reproduce the error locally for debugging.
from kirby-uniform.
Sure, see the attached file. So with the exact state as I set up, it's not working. However, when I change line 11 of templates/home.php to <form action="<?php echo $page->url()?>/<?php echo $page->slug() ?>" method="post">
, it will work. The form will however redirect to (url)/home, which isn't ideal either.
from kirby-uniform.
Your ZIP works for me out of the box with $page->url()
😕 What's your local environment? Do you run the site on an Apache? Are you redirected when you submit the form?
from kirby-uniform.
I'm not redirected after the submit. Currently using XAMPP, but have no idea where to check what version it is I'm running..
from kirby-uniform.
It works for me both using the PHP dev server (PHP 7) and an Apache (PHP 5.6). I'm sorry but as long as I can't reproduce this problem I can't fix it 😕
from kirby-uniform.
Is there any other way I could try debugging it for myself?
It's not that the plugin is now unusable, it's just a small anoying thing which I'd be happy to try finding a fix for :)
from kirby-uniform.
Sure, you can debug away on your own machine. One thing you can check easily is whether the token of the submit button changes each time you submit the form. If it changes there may be something wrong with the guard which decides that the request was invalid and resets the form although it shouldn't.
from kirby-uniform.
@kayspiegel @aufmkolk @wtip @BeSports
I now suspect that a redirect is causing this problem during which all form data is lost. Some server configurations will redirect a request e.g. from example.com/form
to example.com/form/
.
So please try changing your form's action URL from <?php echo $page->url()?>
to <?php echo $page->url()?>/
and see if it works.
from kirby-uniform.
Hey @mzur, like I said in my second post, adding the '/' does the trick for me indeed!
from kirby-uniform.
@BeSports But you added the page slug, too, right?
<form action="<?php echo $page->url()?>/<?php echo $page->slug() ?>" method="post">
It should work without the slug and with the /
suffix only:
<form action="<?php echo $page->url()?>/" method="post">
from kirby-uniform.
Yup, that's indeed the current way I'm doing it :)
from kirby-uniform.
Great, then I'll take this issue as resolved.
from kirby-uniform.
Related Issues (20)
- Invalid CSRF token question HOT 3
- Without redirection errors accumulate over time when form is submitted multiple times HOT 3
- Incompatibility with Kirby 3.6 : Str::template() parameters deprecated HOT 2
- Custom classes HOT 1
- Choose Date Format for Form Fields HOT 3
- PHP Deprecated htmlspecialchars(): Passing null to paramete HOT 4
- Plugin is not moved by `getkirby/composer-installer` HOT 3
- Post/Redirect/Get not working HOT 1
- Character "&" gets "&" HOT 2
- Bug with Honeypots guard and the autocomplete attribute HOT 2
- RCP: "done" closure HOT 5
- Allow body in email action HOT 6
- Distinguish between validation errors and server/action errors HOT 2
- Creation of dynamic property Uniform\Actions\EmailSelectAction::$data is deprecated HOT 1
- Error on form submission after update to PHP 8.1 HOT 2
- Option for a custom message in guards HOT 1
- [K4] Issue with form submission
- [K4] 4.0 Compatibility HOT 9
- Plugin not moved to plugins folder HOT 3
- Translations not working properly HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kirby-uniform.