homepage Welcome to WebmasterWorld Guest from 54.243.23.129
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Page redirect after Xms
php, html form
sharkyvk




msg:4599107
 7:14 pm on Aug 3, 2013 (gmt 0)

Can Any one tell me if the following is possible?

I have an index.php with a html form. Once it is submitted the page index.php gives 5000ms update that the form has been sent. It then redirects to a conditions and terms page. The form data is also sent to my email address and of the user.
What I want to achieve is:

Form is submitted, 5000ms delay with message that form has been sent in index.php, both emails are sent, then redirect to confirmation page showing a summary of the input data of the user. after another 5000ms a redirect to the terms and condition page.

thanks,
Mike

[edited by: jatar_k at 4:51 pm (utc) on Aug 4, 2013]
[edit reason] url unnecessary [/edit]

 

jatar_k




msg:4599261
 4:55 pm on Aug 4, 2013 (gmt 0)

you can do that, though it is very odd, usually we spend time trying to speed things up, not slow them down ;)

you could use something like sleep [php.net] to stall the script

use mail [php.net] to send the emails and header [php.net] to redirect

I wasn't sure which part exactly you were asking about.

sharkyvk




msg:4599301
 9:13 pm on Aug 4, 2013 (gmt 0)

Thx, Jatar,
The update of the subscription shows directly on index.php once the form is submitted, no delay here. index.php stays visible during the 5000ms and then it loads the terms and conditions page.

What I want is to show a confirmationPage.php or html with all the data the user put in the form and nicely styled. The user can read this and also read that they will receive a email with further explination of the subscription. This should stay visible for about 5000ms and then jump to the terms-and-condions-page.html

Readie




msg:4599310
 9:25 pm on Aug 4, 2013 (gmt 0)

Ok, quite simple to do.

Your form posts to confirmationPage.php which just does this:

<?php

// Parse form data and send Email here

header('refresh: 5;url=/terms.php');

?><!-- HTML with a summary of post data -->

Make sure you're not pushing anything to the browser before that header call or you'll get PHP complaining at you.

sharkyvk




msg:4599593
 10:21 pm on Aug 5, 2013 (gmt 0)

Thx Readie,
I don't really understand how to set up the code you showed. Could you explain it more please.
how should i write the parse form data? sending the mail with mail.

sharkyvk




msg:4599650
 8:19 am on Aug 6, 2013 (gmt 0)

Here is a part of my php script

<?php

// Set email variables
$email = $_POST['email'];
$email_to = 'xxxxxxxxxxxxxx@xxxxxxxxxxxxx.xxxxxx';
$email_subject = 'Inschrijving EHBO cursus';
$email_subject_user = 'U bent ingeschreven voor de cursus EHBO en reanimatie aan kinderen';


// Set required fields
$required_fields = array('naam','email','emailControle','telefoon','algemene_voorwaarden');

// set error messages
$error_messages = array(

'naam' => 'Geef uw naam op svp!',
'email' => 'Geef een geldig email op!',
'emailControle' => 'Uw email adres komt niet overeen!',
'telefoon' => 'Geef uw telefoon nummer op svp!',
'algemene_voorwaarden' => 'U moet accoord gaan met de algemene voorwaarden.'
);

// Set form status
$form_complete = FALSE;

// configure validation array
$validation = array();

// check form submittal
if(!empty($_POST)) {
// Sanitise POST array
foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));

// Loop into required fields and make sure they match our needs
foreach($required_fields as $field) {
// the field has been submitted?
if(!array_key_exists($field, $_POST)) array_push($validation, $field);

// check there is information in the field?
if($_POST[$field] == '') array_push($validation, $field);

// validate the email address supplied
if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);

//Eigen opbouw van email check
if ($field == 'emailControle') if($_POST[$field] != $_POST['email']) array_push($validation, $field);
}
//einde eigen opbouw email check

//telefoon check
if (!ctype_digit($_POST['telefoon']) || strlen($_POST['telefoon']) != 10) array_push($validation, $field);

//algemene voorwaarden check
if ($field == 'algemene_voorwaarden') if (!isset ($_POST['algemene_voorwaarden'])) array_push($validation, $field);

// basic validation result
if(count($validation) == 0) {
// Prepare our content string
$email_content = 'Inschrijving EHBO cursus: ' . "\n\n";
$email_content_user = 'Gefeliciteerd met uw inschrijving voor de cursus EHBO en Reanimatie aan kinderen: '. "\n\n";

// simple email content
foreach($_POST as $key => $value) {
if($key != 'submit') $email_content .= $key . ': ' . $value . "\n\n";
if($key != 'submit') $email_content_user .= $key . ': ' . $value . "\n\n";
}

// if validation passed ok then send the email
mail($email_to, $email_subject, $email_content . '', 'From: ' . $email);
// if validation passed ok then send the email to user
mail($email, $email_subject_user, $email_content_user . '', 'From: ' . $email_to);

// Update form switch
$form_complete = TRUE;
}
}

function validate_email_address($email = FALSE) {
return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
}

function remove_email_injection($field = FALSE) {
return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Kunt U het leven van een kind redden? Nee! Volg dan nu een EHBO cursus.</title>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved