manlio Posted January 19, 2015 Share Posted January 19, 2015 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. Link to comment Share on other sites More sharing options...
Wanze Posted January 19, 2015 Share Posted January 19, 2015 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 1 Link to comment Share on other sites More sharing options...
manlio Posted January 19, 2015 Author Share Posted January 19, 2015 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. Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2015 Share Posted January 20, 2015 <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? 1 Link to comment Share on other sites More sharing options...
manlio Posted January 20, 2015 Author Share Posted January 20, 2015 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. Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2015 Share Posted January 20, 2015 I don't know. How does the english url look then? 1 Link to comment Share on other sites More sharing options...
manlio Posted January 20, 2015 Author Share Posted January 20, 2015 English url http://mywebsite.com/en/contacts/contacts-done/ Italian that is working http://mywebsite.com/en/contatti/contatti-invio/ Thank you Link to comment Share on other sites More sharing options...
manlio Posted January 20, 2015 Author Share Posted January 20, 2015 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" > Link to comment Share on other sites More sharing options...
Soma Posted January 20, 2015 Share Posted January 20, 2015 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? 2 Link to comment Share on other sites More sharing options...
manlio Posted January 20, 2015 Author Share Posted January 20, 2015 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now