/    Sign up×
Community /Pin to ProfileBookmark

validate then redirect

Still working on this but, I want to validate a text field of certain characters only, then if everything checks out right then redirect to the next page.

heres what I got so far

[code=php]
<?php
// start the session
session_start();
header(“Cache-control: private”); //IE 6 Fix

// Get the user’s input from the form
$name = $_POST[‘Name’];

// Register session key with the value
$_SESSION[‘Name’] = $name;

/* Validation */

function Name($name){
if(!preg_match(“/[^a-zA-Z_ ]+$/s”,$name)) return TRUE;
else return FALSE;
}

/* Validation */

$error=0; // check up variable

/* get it checking */

if(!Name($name)){
echo “Illegal input $name in “Name””;
$error++; // $error=$error+1;
}

if($error == “0”){
echo ” // i dont know what to put here

}else{
echo “Number of errors: $error”;
}

?>
[/code]

it does the checking but i cant figure out what the code is to redirect…

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@purefanOct 18.2005 — you could try
[code=php]header("Location:http://somewhere.com/index.php"); [/code]
but you cant print anything before this line
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYOct 18.2005 — [code=php]header("Location: http://url.com");[/code]
but becareful, there should be no content sent prior to this

--oops, i didnt see someone already answered the question! :rolleyes:
Copy linkTweet thisAlerts:
@KamuiauthorOct 18.2005 — [code=php]
/* Validation */

$error=0; // check up variable

/* get it checking */

if(!Name($name)){
echo "Illegal input $name in "Name"";
$error++; // $error=$error+1;
}

if($error == "0"){
header ("Location http://site.com/jobsubmission.php");
}
[/code]


tried and dotn work... im inserting the code in the validation part of the code

so theres an 'if' statement leading
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYOct 18.2005 — you forgot the ":" after Location
Copy linkTweet thisAlerts:
@KamuiauthorOct 18.2005 — can i merge two php files so that they work as one?

Basically I want the user to fill out a form, if the name meets the requirements it emails the form data to me. Or can I include the validate part into my form?

Validate.php
[code=php]
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix

// Get the user's input from the form
$name = $_POST['Name'];

// Register session key with the value
$_SESSION['Name'] = $name;

/* Validation */
function Name($name){
if(!preg_match("/[^a-zA-Z_ ]+$/s",$name)) return TRUE;
else return FALSE;
}

/* Validation */

$error=0; // check up variable

/* get it checking */

if(!Name($name)){
echo "Illegal input $name in "Name"";
$error++; // $error=$error+1;
}

if($error == "0"){
header ("Location: http://site.com/file.php");
}
?>
[/code]


Mailerscript.php
[code=php]
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix

// Get the user's input from the form
$name = $_POST['Name'];

// Register session key with the value
$_SESSION['Name'] = $name;

# OPTIONAL SETTINGS
$MailToAddress = "[email protected]";
$redirectURL = "upload.php";
$MailSubject = "Job Submission";
$MailToCC = "";

# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
$w4fver = "1.8.1";
if (preg_match ("/".str_replace("www.", "", $_SERVER["SERVER_NAME"])."/i", $_SERVER["HTTP_REFERER"])) {
$w4fMessage = "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>n<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body>n<font face=3Dverdana size=3D2>n";
if (count($_GET) >0) {
reset($_GET);
while(list($key, $val) = each($_GET)) {
$GLOBALS[$key] = $val;
if (is_array($val)) {
$w4fMessage .= "<b>$key:</b> ";
foreach ($val as $vala) {
$vala =stripslashes($vala);
$w4fMessage .= "$vala, ";
}
$w4fMessage .= "<br>n";
}
else {
$val = stripslashes($val);
if (($key == "Submit") || ($key == "submit")) { }
else { if ($val == "") { $w4fMessage .= "$key: - <br>n"; }
else { $w4fMessage .= "<b>$key:</b> $val<br>n"; }
}
}
} // end while
}//end if
else {
reset($_POST);
while(list($key, $val) = each($_POST)) {
$GLOBALS[$key] = $val;
if (is_array($val)) {
$w4fMessage .= "<b>$key:</b> ";
foreach ($val as $vala) {
$vala =stripslashes($vala);
$w4fMessage .= "$vala, ";
}
$w4fMessage .= "<br>n";
}
else {
$val = stripslashes($val);
if (($key == "Submit") || ($key == "submit")) { }
else { if ($val == "") { $w4fMessage .= "$key: - <br>n"; }
else { $w4fMessage .= "<b>$key:</b> $val<br>n"; }
}
}
} // end while
}//end else
$w4fMessage .= "</font></body></html>";
if (!$email) {$email = $MailToAddress;}
$mailHeader = "From: Job@rn";
$mailHeader .= "Reply-To: $name <$email>rn";
$mailHeader .= "Message-ID: <". md5(rand()."".time()) ."@". ereg_replace("www.","",$_SERVER["SERVER_NAME"]) .">rn";
$mailHeader .= "MIME-Version: 1.0rn";
$mailHeader .= "Content-Type: multipart/alternative;";
$mailHeader .= " boundary="----=_NextPart_000_000E_01C5256B.0AEFE730"rn";
$mailHeader .= "X-Priority: 3rn";
$mailHeader .= "X-Mailer: PHP/" . phpversion()."rn";
$mailHeader .= "X-MimeOLE: Produced By kamuivii.com $w4fverrn";
if ($MailToCC) { $mailHeader .= "Bcc: $MailToCCrn"; }
$mailMessage = "This is a multi-part message in MIME format.rnrn";
$mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730rn";
$mailMessage .= "Content-Type: text/plain; charset="ISO-8859-1"rnContent-Transfer-Encoding: quoted-printablernrn";
$mailMessage .= strip_tags($w4fMessage)."rnrn";
$mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730rn";
$mailMessage .= "Content-Type: text/html; charset="ISO-8859-1"rnContent-Transfer-Encoding: quoted-printablernrn";
$mailMessage .= "$w4fMessagernrn";
$mailMessage .= "------=_NextPart_000_000E_01C5256B.0AEFE730--rn";

if (!mail($MailToAddress, $MailSubject, $mailMessage,$mailHeader)) { echo "Error sending e-mail!";}
else { header("Location: ".$redirectURL); }
} else { echo "<center><font face=verdana size=3 color=red><b>ILLEGAL EXECUTION DETECTED!</b></font></center>";}

?>
[/code]
Copy linkTweet thisAlerts:
@purefanOct 18.2005 — you can [i]include[/i] one file into another using the require tag:
[code=php]require ("MyPage.php");[/code]
it will then work as if you had typed all MyPage.php into the current document.

LiLcRaZyFuZzY: hehe i answered first! I answered first! just kidding ?
Copy linkTweet thisAlerts:
@SheldonOct 19.2005 — If you use an include or require to pull the validation and email script it will run it at the same time as it creates the form. what you want to to if you want the code on the same page is something like...

[code=php]
<?php
if (isset($_POST['submit'])) {

//this will check if the user has submitted the form

###Validation script and email to user if valid###


} else {

//so they havnt submitted the form yet huh?
//well then create the form so that they can!!

###Form script here ####
//your form script will redirect to the same pager name as the file is called. eg:

<form method="post" action="thispage.php">


//end action
}
?>
[/code]

You will want to run your validation script in a if/else situation

so if vaild send email else Location: /mailscript.php
×

Success!

Help @Kamui spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...