Hey everyone, and more specifically @mzur
Iām having a hell of a time with the Uniform plugin at the moment. To give more detail Iāve more or less taken the basic example from github and reproduced it on my site (added a couple of fields). My issue arises though when I try to use Uniform on any page that isnāt ādefaultā - if you go to the default page http://ckautosales.ca/default and submit the form it will work as expected, however if you go over to http://ckautosales.ca/contact which has the exact page structure the form doesnāt send, the process seems to work but nothing is submitted.
The controller goes something like this, I should also note that the controllers are named for their respective pages(default, contact):
<?php
return function($site, $pages, $page) {
$form = uniform('contact-form', [
'required' => [
'name' => '',
'last-name' => '',
'phone' => '',
'_from' => 'email'
],
'actions' => [
[
'_action' => 'email',
'to' => 'me@workemail.com',
'sender' => 'info@ckautosales.ca',
'subject' => 'New Message From The Contact Form On CKAuto Sales'
]
]
]);
return compact('form');
};
I'm certain that I'm missing something absolutely fundamental here, and any help would be appreciated. Thanks
First off take a look at this thread on how to make your code look good here in the forum
I donāt know (yet) what the problem might be here but I have a suggestion that might resolve it anyway. Since the form is displayed on multiple pages with different templates I suppose you already have a snippet for the form that you include in each template. In this case you can consider putting the controller code of uniform(...) directly in the snippet, too. Although this violates the āseparation of concernsā you donāt have to duplicate your code for each template and if it works on one page, it works on all pages.
Ahaha thank you, Iāve been wondering about that.
So I tried putting the controller code directly into the template, and that breaks my pages. I suppose my example that the form working on one page and not working on another was misleading though. I donāt actually need this form to work on multiple pages, I just need it to work on the contact page.
I just found it curious that the form only works if it is located on the ādefaultā page. Ultimately there wonāt be anything on the default page, but for the moment thatās the only place that the form is working.
Thanks for getting back to me, Iām happy to provide any code, or even the project in a zip if you think it would help.
Iāve been looking through other topics and github issues to see if anyone is having the same problem I am and so far thereās been no luck. It seems like a really weird issue and thatās why Iām assuming that itās user error on my part.
If I can clarify anything else for you, just let me know. Thanks.
So, before you break your brain trying to figure this one out. The issue, or at least this particular issue lies with having a rel=āiconā link in the head. If Iāve got the link with an href the form redirects but nothing is sent, if I remove the link altogether nothing happens with the form.
This is a weird fringe issue, and if you donāt have any ideas, Iām not too concerned, as I now have the form functioning, having the ability to have the form function and have a favicon would be great though, so if youāve got any ideas Iām all ears.
That being said, Uniform is great now that Iāve isolated this issue, so thanks for your hard work.
That sounds like there is an unwanted GET request being sent. If there is a request that does not supply the Uniform token, Uniform will generate a new token which invalidates the old one. If you then attempt to submit the form with the old token Uniform will ignore it.
Thatās a real pain and would be solved if Uniform would only listen to POST requests. Unfortunately I donāt have the time to do a major overhaul of the plugin right nowā¦
Take a look at all the requests in the network tab of the developer tools. You should be able to identify any unwanted requests there. If you canāt find anything send me a ZIP in a PM with a description on how to reproduce the problem and Iāll have a look.