Trouble With Uniform Plugin

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 :wink:

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.