Submitting Form: PHP header(Location: …)
Posted: June 11th, 2015 | Author: Julia | Filed under: Development, Tips and Tricks | Tags: bloginfo('template_url'), form, form submit, header, header location, WordPress | No Comments »Once I got a weird trouble with submitting contact form.
My website was powered by WordPress and the contact form was placed at the default page (single page design), so I want the form to submit to the page itself that the form is on.
My form:
-
<form action="<?php bloginfo('template_url'); ?>/php-form-submit.php/" method="post">
-
…
-
</form>
File php-form-submit.php sends the form (and placed at the theme directory). After successful validation and emailing the form I would like to open ‘Thank you’ page.
It’s enough to get the URL with bloginfo(‘template_url’) for WordPress usually:
-
header('Location: ' . bloginfo('template_url') . '/thank-you/');
(where is ‘thank-you’ – my ‘Thank you’ page). Strangely, I got fatal error here – the function bloginfo() was undefined.
The solution:
I used HTTP_HOST.
$_SERVER[‘HTTP_HOST’] gives the domain name through which the current request is being fulfilled and relates directly to the request:
-
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/thank-you/');
works like a charm.
Leave a Reply