-3

Hi I'm trying to implement a simple contact form on my website using this tutorial - http://rosstanner.co.uk/2012/11/build-simple-contact-form-html-php-bootstrap/

Trouble is after the user submits an action I need the user to be redirected to an anchor ID down the bottom of the page i.e. www.somepage.com/index.php#contact

The redirect is this...

header('Location: index.php?s='.urlencode('Thank you for your message.'))

I've tried...

header('Location: index.php?s='.urlencode('Thank you for your message.')'#contact')

...but to no avail.

When I try to add anything like this to make it scroll down to the anchor bookmark the browser hangs on the contact-form-submission.php page (separate php page for the contact form logic)

I'm sorry if I've explained this in a convoluted. I don't actually know PHP!

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
ternonlerwen
  • 113
  • 7
  • 9
    You missed concatenation operator `.` before your '#contact' so the script fails. Maybe that's why browser hangs. – Kamil Szot Apr 19 '13 at 08:19
  • Welcome to Stackoverflow! Please use the search before asking a question. This website works by collecting common questions over time, not to add them over and over again. – hakre Apr 19 '13 at 08:21
  • 3
    This question isn't a duplicate of the linked question. In the linked question the OP wants to read the current hash and mirror it in the new URL (which isn't possible). OP here doesn't care what the hash already was, he just wants to set a new one (which definitely is possible) – Gareth Apr 19 '13 at 08:24
  • @Gareth: Yes, the better duplicate is this one: [URL Fragment and 302 redirects](http://stackoverflow.com/q/2286402/367456) . – hakre Apr 19 '13 at 08:29
  • I did do a search but I'm lost when it comes to PHP. I didn't understand the duplicate thread. Extra specificity in adding questions like these to the pool can help novices like me who don't know exactly what to search for. – ternonlerwen Apr 19 '13 at 08:39
  • @user2298352 Can you expand on what "the browser hangs" means? Do you get a white screen or what? – DaveRandom Apr 19 '13 at 08:40
  • The browser went to the contact-form-submission.php page and the page failed to cease loading (yes, white page displayed) – ternonlerwen Apr 19 '13 at 08:43
  • BTW thanks Kamil and Jack, it was just the . operator I was missing before the '#contact' – ternonlerwen Apr 19 '13 at 08:44
  • white page = page of death: Please see [PHP Error Reference](http://stackoverflow.com/q/12769982/367456) if you run into problems, it has good tips. (see first entry of the list ;)). – hakre Apr 19 '13 at 08:45

1 Answers1

7

The correct syntax is this:

header('Location: index.php?s=' . urlencode('Thank you for your message.') . '#contact');
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309