Page 1 of 1
how do I make PHP load a different piece of HTML/PHP?
Posted: Wed Sep 29, 2004 5:02 pm
by percepts
Is there any way to make PHP load a different html file based on selection made in a form?
i.e. after the submit button in my form is pressed I would like to load one of two other pieces of html depending on the selection made in the form. I need to pass the forms variables as well.
TIA
percepts
Posted: Wed Sep 29, 2004 5:07 pm
by John Cartwright
you can look into
Code: Select all
<?php
switch ($_POST['variable']) {
case 'variable1':
include 'page1.php';
break;
case 'variable2':
include 'page2.php';
break;
default:
include 'form.php';
break;
}
?>
This is one way to do it, the possiblities are limitless.. it all depends what you are comfortable with and what your form looks like, show us your form plz.[/list]
Posted: Wed Sep 29, 2004 5:22 pm
by percepts
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
the PHP currently sends an email but I want to change it to load one of two different pages depending on the payment method selected.
Top of file is currently as follows:
I will take out the email processing in due course so if validation is OK then I would go to other page.
thanks
Code: Select all
<?PHP
if ($_SERVERї'REQUEST_METHOD'] == 'GET' || $qfirst == 'yes') {
$qfirst = 'no';
$galid = eregi_replace('_',' ',$qgalid);
$imgtitle = eregi_replace('_',' ',$qimgtitle);
$imgtype = eregi_replace('_',' ',$qimgtype);
$imgmountsize = eregi_replace('_',' ',$qimgmountsize);
$imgprintsize = eregi_replace('_',' ',$qimgprintsize);
$imgprice = eregi_replace('_',' ',$qimgprice);
$imgformat = $qimgformat;
$imgthis = $qimgthis;
$img = 'photography/blackandwhite/'.$qgalid.'/pics/'.$qimgtitle.'.'.$qimgformat;
$doc = 'photography/blackandwhite/'.$qgalid.'/artprintsphotosimages'.$qimgthis.'.php';
$Frame = "";
$Email = "";
$Telephone = "";
$Name = "";
$Address = "";
$Requirements = "";
$subject = "";
$to = "";
$msg = "";
$mailheaders = "";
$querystr = $_SERVERї'QUERY_STRING'];
} else {
$validate = "yes";
$qframingsel = '';
if ($Framing == 2) {
$qframingsel2 = 'selected';
}
if ($Framing == 3) {
$qframingsel3 = 'selected';
}
$qmethodsel = '';
if ($Method == 2) {
$qmethodsel2 = 'selected';
}
if ($Method == 3) {
$qmethodsel3 = 'selected';
}
}
$Email = $stickyemail = ereg_replace(" ", " ", trim($Email));
$Telephone = $stickytelephone = ereg_replace(" ", " ", trim($Telephone));
$name = $Name = $stickyname = ereg_replace(" ", " ", trim($Name));
$Address = $stickyaddress = ereg_replace(" ", " ", trim($Address));
$Requirements = $stickyrequirements = ereg_replace(" ", " ", trim($Requirements));
$refer = $_SERVERї'HTTP_REFERER'];
$errtxt = "<span class='spamtxt'> N.B. without a valid email address I can not respond to your enquiry</span>";
$size = getimagesize($img);
$imgheight = 90;
$imgwidth = ($sizeї0] / $sizeї1]) * $imgheight;
if ($validate == "yes") {
$errtxt = "";
if ($Address == "" ) {
$errtxt = "Your Address is required"; }
if ( $stickytelephone == "" || !ctype_digit(ereg_replace(" ", "", $stickytelephone))) {
$errtxt = "Telephone number must be numeric"; }
if ($Email == "" || !eregi("^ї_\.0-9a-z-]+@(ї0-9a-z]ї0-9a-z-]+\.)+їa-z]{2,6}$",$Email)) {
$errtxt = "Your Email Address is invalid"; }
if ($Name == "" ) {
$errtxt = "Your Name is required"; }
if ($Method == "1" ) {
$errtxt = "Please select a Payment Method"; }
if ($Framing == "1" ) {
$errtxt = "Please select a Framing option"; }
}
if ($errtxt == "") {
if(getenv(HTTP_X_FORWARDED_FOR))
{$user_ip=getenv("HTTP_X_FORWARDED_FOR");}
else
{$user_ip=getenv("REMOTE_ADDR");}
$to = "spam@visualperception.co.uk";
$subject = "Web Order";
$msg = "\n\nUser IP: $user_ip\n\n\n\n";
$msg .= "Name:\n";
$msg .= "$name\n\n";
$msg .= "Adress:\n";
$msg .= "$Address\n\n";
$msg .= "Tel: $Telephone\n\n";
$msg .= "Image Title: $imgtitle\n";
$msg .= "Image Mount: $imgmountsize\n";
$msg .= "Image Size: $imgprintsize\n";
if ($Framing == 2) {
$msg .= "Framing: Black Aluminium plus £40\n";
}else{
$msg .= "Framing: No Frame\n";
}
$msg .= "Image Price: $imgprice\n\n";
$msg .= "Requirements:\n";
$msg .= "$Requirements\n\n";
$mailheaders .= "X-Sender: Visual Perception\n";
$mailheaders .= "X-Mailer: PHP Order Form\n";
$mailheaders .= "From: "".$name."" <".$Email.">\n";
$mailheaders .= "Reply-To:: "".$name."" <".$Email.">\n";
$mailheaders .= "Mime-Version: 1.0\n";
$mailheaders .= 'Content-type: text/plain; charset="us-ascii"\n';
if(SendMail($to, $subject, $msg, $mailheaders)) {
$errtxt = "Your Order has been sent. Thank you.";
} else {
$errtxt = "There was a problem sending your Order. Please Telephone or try again again later"; }
}
function SendMail($to,$subject,$msg,$mailheaders)
{
return(mail($to,$subject,$msg,$mailheaders));
}
$response = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo $response;
?>
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Wed Sep 29, 2004 5:26 pm
by pickle
I'll try and beat ~feyd to this: put your code in [syntax=php]tags for much easier reading[/syntax]
Posted: Wed Sep 29, 2004 5:48 pm
by percepts
oops,
next time i'll use the php button...
percepts