Web Design Forum: Couple of php questions :) - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Couple of php questions :) Rate Topic: -----

#1 User is offline   Lovelock 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 307
  • Joined: 12-May 11
  • Reputation: 7
  • Gender:Male
  • Location:Southampton, UK.
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 04 January 2012 - 12:10 PM

Hello, im just starting out with php so bare with me!

Im making the contact form side of my site,

When clicking submit, it loads mailer.php which displays:

echo "Data has been submitted to $to!";


However... i wish it to redirect back onto my website after say 5 seconds.

Is this possible with php?

Ive tried adding a sleep into it but it doesnt load the mailer.php it just waits.

I added it like so:

<?php
if(isset($_POST['submit'])) {
$to = "craiglovelock54@hotmail.co.uk";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
sleep(10);//seconds to wait..
header("Location:http://www.vinylpenguin.co.uk/page.php");
} else {
echo "blarg!";
}
?>


I expected it to load the page then run the sleep part but it doesnt.

Any help?

This post has been edited by Lovelock: 04 January 2012 - 12:10 PM

0

#2 User is offline   paulb 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 39
  • Joined: 18-September 09
  • Reputation: 9
  • Gender:Male
  • Location:Leeds
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 04 January 2012 - 12:51 PM

Hi Lovelock

I think the redirection isn't occuring as the php headers have already been sent and an error is being generated.

Have you got php error reporting turned on? If not I would advise you to turn it on
http://php.about.com...r_reporting.htm

Your idea is fine - your code just needs a few tweaks.

A good example of a basic form with a similar problem can be found here:
http://stackoverflow...p-form-redirect

The header example produced by blasteralfred is equivalent to your code
sleep(10);//seconds to wait..
header("Location:http://www.vinylpenguin.co.uk/page.php");

Paul

This post has been edited by paulb: 04 January 2012 - 12:51 PM

0

#3 User is online   kensha 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 870
  • Joined: 12-August 10
  • Reputation: 17
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 04 January 2012 - 01:04 PM

Mind if I say, thank you for the sleep() function.

I didn't knew of that function before and indeed it must be your location, all seems to be fine.

This post has been edited by kensha: 04 January 2012 - 01:05 PM

0

#4 User is offline   Lovelock 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 307
  • Joined: 12-May 11
  • Reputation: 7
  • Gender:Male
  • Location:Southampton, UK.
  • Experience:Intermediate
  • Area of Expertise:Designer

Posted 04 January 2012 - 02:27 PM

View Postpaulb, on 04 January 2012 - 12:51 PM, said:

Hi Lovelock I think the redirection isn't occuring as the php headers have already been sent and an error is being generated. Have you got php error reporting turned on? If not I would advise you to turn it onhttp://php.about.com/od/troubleshooting/qt/php_error_reporting.htm Your idea is fine - your code just needs a few tweaks. A good example of a basic form with a similar problem can be found here:http://stackoverflow.com/questions/4943768/simple-php-form-redirect The header example produced by blasteralfred is equivalent to your code sleep(10);//seconds to wait.. header("Location:http://www.vinylpenguin.co.uk/page.php");Paul


Hello, it redirects, but it doesnt show the php page.

I still want it to go to the php page but then redirect back to main site. If that makes sense.

So without the redirection, it goes to a blank page with the echo output of "Your message is sent bla"

I will style this page to look like the main page but want it as a confirmation process.

With the redirection where it is, on clicking submit / send etc, it waits 10 seconds then goes to main page. Missing out the php page :)

EDIT: Sorted with this instead of the sleep:

header("Refresh: 3; url=\"http://www.vinylpenguin.co.uk/page.php\"");

This post has been edited by Lovelock: 04 January 2012 - 03:10 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users