Jump to content

Recommended Posts

Posted

Hi, in a multilanguage site (italian - english), I have a contact form that on submit send post variables to another PW page.

Everything works for the italian part, but when I switch to english (that it is not the default language) , when I submit the form the post variables are empty.

Seems that PW operates a redirect and lose the variables.

How can avoid this?

Thank you.

Posted

ProcessWire performs a redirect if your URL where you send the form doesn't have a trailing slash.

Is this the case? You can also use DevTools in Chrome or a Tool like Firebug and check what's going on with your request.

Cheers

  • Like 1
Posted

Thank you Wanze, my link in the form is like this and to me seems right

<form role="form" action="../<?php $config->urls->root;?>contatti/contatti-invio/" method="post" >

For me it is strange that the form works perfectly in italian, and when I switch to english and submit it doesn't work.

When I send form from English the mail that arrives misses all the post fields and the saem hapen in the confirmation page after the form submission.

If this is a normal behaviour maybe I could change the form address using php based on the language selected.

Just guessing.

Posted
<form role="form" action="../<?php $config->urls->root;?>contatti/contatti-invio/" method="post" >

will be like...

..//contatti/contatti-invio/

?

Apart from that you have the italian url here so I'm not sure how you get the english one?

  • Like 1
Posted

Thanks Soma, you are right, my bad...

I have corrected in 

<form role="form" action="../contatti/contatti-invio/" method="post" >

but still doesn't work when I change to english language.

Posted

I tried also with something like this but still doesn't work

<form role="form" action="<?php  if ($user->language == '1061') {echo '../contatti/contatti-invio/';} else {echo '../en/contacts/contacts-done/';} ?>" method="post" >
Posted

Why do you need the "../"?

Shouldn't it be absolute from domain root 

"/en/contact/contacts-done/"

Since you say you loose the post vars, try to inspect in console while posting, it tells you if it get's redirected. You just have to find the correct url that doesn't do it.

Usually you just use $page->url in the language you are and post it to itself, then redirect after it was successful to show a success message. It's  called PRG pattern http://en.wikipedia.org/wiki/Post/Redirect/Get to avoid getting send again when using back button or refresh etc.

Edit: Just wanted to mention since I don't think it's good to post a contact form to a "done" page, what if there's form errors you want to show the form again?

  • Like 2
Posted

Thank you Soma, you were really helpful.

This is for sure the best way, thank for your help, I try to use this approach instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...