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 and submit the form it will work as expected, however if you go over to 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' => '', 'sender' => '', '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.