Forum

Thread tagged as: Forms

Redirecting .php to no extension results in Forms not working

As per this closed thread:- https://forum.grabaperch.com/forum/04-06-2017-forms-stop-working-when-php-extension-redirected-to-non-php

I've got the exact same problem word for word.

I am using this in the .htaccess file (amongst other entries)

# browser requests PHP redirect to non .php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

However, as a result forms (using the Forms App) are no longer getting submitted or stored.

I remove those lines and everything works fine.

I am using the the rules to redirect pages being directly requested with .php to non .php for SEO purposes as my site audit flags duplicate content because it is seeing both .php and non .php as 2 different pages.

Any suggestions?

Drew did reply with:

"The form is being submitted, you're just throwing the data away when you redirect.

The solution would be to submit the form to the URL you want it to go to without a redirect."

I'm struggling to see where this is set. Any pointers? I want the form to use the Forms App so it stores responses and sends templated emails.

Thanks.

Joe Proctor

Joe Proctor 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

On the perch:form tag, add action="" with the URL you want the form to submit to.

Hi Drew, many thanks for the prompt reply.

Saw you mention similar in another thread, the thing is I'm a bit stumped as to what the URL should be? Normally I'd have a handler, e.g contact-form-handler.php which would send an email. Obviously Perch Forms negates the need for the handler file assumedly as it has its own that logs it in the db and fires an email off. However I'm not sure where this file is and how to reference it.

Thanks.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Joe,

The URL in the action attribute could be any page you want. It could be the website's home page, another page on the website or even the same page where the form is (perhaps to display a success message with <perch:success>).

To another page:

<perch:form id="contact" method="post" app="perch_forms" action="/another-page">

Same page:

<perch:form id="contact" method="post" app="perch_forms" action="#success">

Ah I see, thanks Hussein that has sorted it. I'd assumed changing the action would bypass Perch handling the form, but it appears not!

Drew McLellan

Drew McLellan 2638 points
Perch Support

As long as the page it posts to includes the Perch runtime, then Perch will do its thing.