Form Action URI in Grav

My contact form is at the URI /contact-me (which means the page file is at /user/pages/03.contact-me/contact.md and the template is at /user/themes/br/templates/contact.html.twig).

I want to point the form action to /user/themes/br/php/mandrill_send.php but when I put that in the action field I end up at http://user/themes/br/php/mandrill_send.php which doesn’t seem to be recognized as a page. It’s certainly not a page as in /user/pages/.

How do I point to that action script in Grav? That is, how do I resolve Grav’s routing structure to end up in the right place for the form action?

can you paste the html with the form action in it?

<form name="contact-form" method="post" action="mandrill_send.php" data-parsley-validate>

This works with the script at the site’s root. But I want to move it deeper and can’t figure out a URI that works.

well you need a path in the action… That’s a URL, so you need to put a relative URL perhaps something like:

<form name="contact-form" method="post" action="{{ theme_url }}/php/mandrill_send.php" data-parsley-validate>

{{ theme_url }}! That’s the trick I needed. Thanks. Now off to Christmas Eve for you. :slight_smile:

Dang! That sends the browser to http://localhost/user/themes/br/php/mandrill_send.php which throws a 404 error.

True, by default we are blocking access to PHP in the user folder for security reasons. You would have to remove |user or |php in this line of the .htaccess file.

# Block access to specific file types for these folders
RewriteRule ^(system|user|vendor)/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$ error [L]

OK. So where’s a “safe” place to be putting my own PHP? /vendor/mandrill/ might be overwritten?

How is it that PHP in /user/plugins/ can run?

maybe create a folder at the root of your Grav installation, like /mandrill ? You would have to use {{ base_url_relative }}/mandrill/blahblah.php for your path though.

:slight_smile: That’s where I had it before I decided to move it all within my theme folder and not loose at the root.