About design and nearby

Submitting Form: PHP header(Location: …)

Posted: June 11th, 2015 | Author: | Filed under: Development, Tips and Tricks | Tags: , , , , , | 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:

  1. <form action="<?php bloginfo('template_url'); ?>/php-form-submit.php/" method="post">
  2. </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:

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

  1. header('Location: http://' . $_SERVER['HTTP_HOST'] . '/thank-you/');

works like a charm.

Share Button

Check Related Posts:


Leave a Reply


  • 4 × = thirty two

Looking for a Freelance UX & UI designer for your project? I’m ready to jump onboard!

Let's discuss your project now