Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit & Redirect not working as expected (3.0.5) #355

Closed
yatiac opened this issue Jun 25, 2019 · 38 comments
Closed

Submit & Redirect not working as expected (3.0.5) #355

yatiac opened this issue Jun 25, 2019 · 38 comments

Comments

@yatiac
Copy link

yatiac commented Jun 25, 2019

The submit action is not working as expected when there is no explicit redirection, the base url was removed in v3.0.5 and this is causing an issue when just submiting but no redirecting. (it was working fine in v3.0.4)

@rhukster
Copy link
Member

If you have a reset: true make sure it's NOT after the redirect: in the form actions.. it will clear the redirect out.

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

this is my form:

title: Contacto
form:
    name: contact
    fields:
        name:
            label: Nombre
            placeholder: 'Introduzca su nombre'
            autocomplete: 'off'
            type: text
            validate:
                required: true
        email:
            label: Email
            placeholder: 'Introduzca su e-mail'
            type: email
            validate:
                required: true
        message:
            label: Mensaje
            placeholder: 'Introduzca su mensaje'
            type: textarea
            validate:
                required: true
    buttons:
        submit:
            type: submit
            value: Enviar
            classes: button
    process:
        email:
            subject: '[Contacto desde Web] {{ form.value.name|e }}'
            body: '{% include ''forms/data.html.twig'' %}'
        message: 'Gracias por su interés, estaremos contactándolo en breve'

and it was working in v3.0.4

@rhukster
Copy link
Member

Dropped your form into my test site. Worked fine:

Image 2019-06-25 at 3 06 39 PM

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

is your website in the root folder of your webserver? I have mine inside a 'grav' folder and when redirected it is removing the base url (a.k.a 'grav' folder in the url)

@rhukster
Copy link
Member

Nope, actually in a subfolder. The thing is that it should not be redirecting at all, it should be submitting to the page the form sits on, then the message should show up on that form on when successfully submitted.

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

For some reason it is redirecting for me.

I think it could be related to this commit: f917a18

@rhukster
Copy link
Member

Try manually reverting that fix, and then you will know for sure.

@rhukster
Copy link
Member

Also inspect your form before you submit, Is the action wrong there? what does it look like?

Image 2019-06-25 at 3 18 13 PM

@rhukster
Copy link
Member

Do you have a custom_base_url: set in system.yaml or something?

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

the action seems to be wrong:
image
I manually changed it to /grav/contacto and it worked fine

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

also, I dont have custom_base_url: set
image

@rhukster
Copy link
Member

So did reverting that fix, make things work as expected?

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

Yes, it did

@rhukster
Copy link
Member

ok try this instead:

{% set action = form.action ? url(form.action) : page.rawRoute() ~ uri.params %}

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

that didn't work

@rhukster
Copy link
Member

yah its not falling back, it's the action in the form object, just not sure why yours is not working when it does on mine and similar setup.

@rhukster
Copy link
Member

BTW what version of Grav are you running?

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

1.6.11

@rhukster
Copy link
Member

Anything else you can tell me about the your setup? webserver? platform? any vhosts? anything special in how you configured things? I just can't replicate your issue :(

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

I don't have anything special at all, the site is installed in a grav folder in an ubuntu server runing php 7.2

interesting thing, it was working in v3.0.4 and reverting the commit makes it work again so it is confirmed is f917a18

@rhukster
Copy link
Member

yah, but the thing is that its now using a 'smarter' function in URL which should append the 'root', ie grav/ in your case in front of the page route. This is what it does for me. The issue is the way we had it before, it inserted the root no matter what the route was, so there were scenarios where the grav/ root was already in the URL, so you ended up with double: grav/grav/contacto for example. It's smarter now to only add it if it needs it.... but for you its not adding it at all...

Can you turn on your debugger and add this in the user/plugins/form/templates/forms/default/form.html.twig file under the set action:

{{ dump(uri.rootUrl) }}

It should output /grav in the messages panel

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

it does

@rhukster
Copy link
Member

rhukster commented Jun 25, 2019

so if you put this: what is the output:

{{ dump(url('/contacto')) }}

??

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

image

@rhukster
Copy link
Member

see my edit.. forgot to wrap it in () the first time.

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

sorry, I missed it, it outputs /contacto

@rhukster
Copy link
Member

Well this makes no sense... We use this url() twig function all over the place, and never had any reports that its unreliable, or returns wrong results.

Can you please ZIP up your entire site and send to me at rhuk at getgrav dot org?

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

Is there anything else I can send you instead of the whole site?

Also, thank you so much for your help troubleshooting this, right now it is working with the manual revertion.

@rhukster
Copy link
Member

to really recreate your setup, i need your whole site. if you want to remove any other pages other than the ones in question that's fine, they won't impact. but need config/plugins/overrides etc

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

My email client is blocking it.

@rhukster
Copy link
Member

Drop it on dropbox/gdrive/onedrive/etc and send me a link?

@yatiac
Copy link
Author

yatiac commented Jun 25, 2019

Done

@rhukster
Copy link
Member

rhukster commented Jun 26, 2019

Thanks that helped a tonne. I figured out the issue as soon as I loaded your page. So the problem is that the Grav url() twig function is handling things correctly, but you are using a Gantry theme, and that has it's own url() function that is not taking the site's base_url [$uri->rootUrl()] into account.

This is actually a bigger "Gantry on Grav" issue that we need to get resolved. So i'm going to ping @mahagr about this as it will undoubtedly cause other problems with Grav-based Gantry themes where the url() function is used.

BTW, I had JS errors in admin and had to reinstall the admin plugin via direct-install to resolve. I suspect you are uploading files via FTP or something and that is not very reliable. Better to upload the ZIP and use a local file manager UI to extract the files. Or better yet, use SSH and GPM in CLI, or GPM via the admin.

@mahagr mahagr self-assigned this Jun 26, 2019
@mahagr
Copy link
Member

mahagr commented Jun 26, 2019

@rhukster It looks like that Gantry has better support for URLs outside of the sites than Grav -- Grav always assumes that all the paths are in the Grav site, Gantry supports:

All of this said, we really need to stop using url() for routes -- it'll not work with multi-lang for example.

@yatiac
Copy link
Author

yatiac commented Jun 27, 2019

Thank you for all your help!

@virusx
Copy link

virusx commented Jul 4, 2019

I had an issue after updating from Form 3.0.3 to 3.0.7.
I checked with WinMerge the difference between the update and the previous plugin.
I tracked down the error and it was caused by the update in "user\plugins\form\templates\forms\default\form.html.twig"

from {% set action = form.action ? base_url ~ form.action : base_url ~ page.route ~ uri.params %}
to {% set action = url(form.action ?: page.route ~ uri.params) %} (3.0.3 version)

As soon as I copied back this line, the plugin worked and I found this thread.
I'm using Ceevee template with all last update in GRAV and plugins.

@rhukster
Copy link
Member

rhukster commented Aug 9, 2019

Should be fixed in next in develop branch/next release

@NicoHood
Copy link
Contributor

NicoHood commented Jan 9, 2021

This is fixed now, right?

@mahagr mahagr closed this as completed Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants