Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Form Action URI in Grav

Started by Muut Archive 11 years ago · 9 replies · 403 views
11 years ago

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?

11 years ago

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

11 years ago

<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.

11 years ago

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

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

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

11 years ago

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

11 years ago

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.

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

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?

11 years ago

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.

11 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1318 9 years ago
Archive · by Muut Archive, 9 years ago
2 915 9 years ago
Archive · by Muut Archive, 9 years ago
2 4044 9 years ago
Archive · by Muut Archive, 9 years ago
1 2920 9 years ago
Archive · by Muut Archive, 9 years ago
3 1103 9 years ago