Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Couple of php questions :)

Featured Replies

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?

Edited by Lovelock

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

Edited by paulb

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.

Edited by kensha

  • Author

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\"");

Edited by Lovelock

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.