NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page small php question

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 12-02-2007, 03:41 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: Florida
Posts: 233
TeviH is an unknown quantity at this point
 



small php question


Hello,

I am not exactly a php expert, and this is probably a very simple thing to do. I am using http://formtoemail.com for a simple php form script on my website. I am using it to submit an order form. (not secure; no payment transaction)

The question is, how can I prevent items with a value of "val0" from being sent in the form? Basically, that just means the customer doesn't want it, so, there's no need to have that sent in the email. Since there's a pretty long list of products (about 25), it can be tiresome to look for the items with values of "val2" "val3" etc. (I need to use the "val" prefix, rather than a number).
????: NamePros.com http://www.namepros.com/programming/402479-small-php-question.html

You can view it online over here: http://www.rukiscookies.com/order.php

Thanks!
__________________
www.headlinercreative.com
TeviH is offline  
Old 12-02-2007, 03:54 PM   #2 (permalink)
Munky Designs
Join Date: May 2005
Posts: 996
Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough
 



post the code that sorts the values and sends it, thats be helpful

but im sure a simple if statement would suffice
Albino is offline  
Old 12-02-2007, 05:49 PM THREAD STARTER               #3 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: Florida
Posts: 233
TeviH is an unknown quantity at this point
 



Sure! Here:

PHP Code:
<?php



$my_email 
"yourname@yourdomain.com";
$continue "/";

$errors = array();

if(
count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

function 
recursive_array_check_header($element_value)
{

global 
$set;

if(!
is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set 1;}}
else
{

foreach(
$element_value as $value){if($set){break;} recursive_array_check_header($value);}

}

}

recursive_array_check_header($_REQUEST);

if(
$set){$errors[] = "You cannot send an email header";}

unset(
$set);

// Validate email field.

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

if(
preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

$_REQUEST['email'] = trim($_REQUEST['email']);

if(
substr_count($_REQUEST['email'],"@") != || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

// Remove leading whitespace from all values.

function recursive_array_check(&$element_value)
{

if(!
is_array($element_value)){$element_value ltrim($element_value);}
else
{

foreach(
$element_value as $key => $value){$element_value[$key] = recursive_array_check($value);}

}

return 
$element_value;

}

recursive_array_check($_REQUEST);

// Check referrer is from same site.

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

// Check for a blank form.

function recursive_array_check_blank($element_value)
{

global 
$set;

if(!
is_array($element_value)){if(!empty($element_value)){$set 1;}}
else
{

foreach(
$element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!
$set){$errors[] = "You cannot send a blank form";}

unset(
$set);

// Display any errors and exit if errors exist.

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!
defined("PHP_EOL")){define("PHP_EOL"strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" "\n");}

// Build message.

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
????: NamePros.com http://www.namepros.com/showthread.php?t=402479

$message build_message($_REQUEST);

$message $message PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";

$message stripslashes($message);

$subject "FormToEmail Comments";

$headers "From: " $_REQUEST['email'];

mail($my_email,$subject,$message,$headers);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<title>Form To Email PHP script from FormToEmail.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#ffffff" text="#000000">

<div>
<center>
<b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
????: NamePros.com http://www.namepros.com/showthread.php?t=402479
<br>Your message has been sent
<p><a href="<?php print $continue?>">Click here to continue</a></p>
Thanks!!
__________________
www.headlinercreative.com
TeviH is offline  
Old 12-02-2007, 06:50 PM   #4 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,615
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




I have not read your script, but i think the solution is
PHP Code:
$message='';

$message='hello dear customer';
????: NamePros.com http://www.namepros.com/showthread.php?t=402479

if (
checkbox_1_is_checked) {
   
$message.=' - '.append_your_item_1_here;
}

if (
checkbox_2_is_checked) {
   
$message.=' - '.append_your_item_2_here;
}

send_the_mail(); 
__________________
xrvel is offline  
Old 12-02-2007, 09:43 PM THREAD STARTER               #5 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: Florida
Posts: 233
TeviH is an unknown quantity at this point
 



I'm not sure Iknow what you mean, but it sounds like you would have me write out a special snippet of code for each form field... I would rather have a universal line of code that basically says, "if any form field has a value of "val0" do not bother writing out that information. We really don't care."



Any other ideas?
__________________
www.headlinercreative.com
TeviH is offline  
Old 12-02-2007, 10:28 PM   #6 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,615
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




First, name your first checkbox with cb01, 2nd checkbox with cb02, ...
(your checkboxes do not have name)

now modify the build_message() section
PHP Code:
<?php
function build_message($request_input){
????: NamePros.com http://www.namepros.com/showthread.php?t=402479
    if(!isset(
$message_output)){
        
$message_output ="";
    }
    if(!
is_array($request_input)) {
        
$message_output $request_input;
    } else { 
        foreach(
$request_input as $key => $value){
            if(!empty(
$value)){
                if(!
is_numeric($key)) {
                    
$add=true;
                    if (
preg_match('/^cb([\d]+)/i',$key,$match)) {
                        
// if is our special checkbox
                        
if ($value!='on') {
                            
// if it is not checked, do not add
                            
$add=false;
                        }
                    }
                    if (
$add) {
                        
$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;
????: NamePros.com http://www.namepros.com/showthread.php?t=402479
                    }
                }else{
                    
$message_output .= build_message($value).", ";
                }
            }
        }
    }
    return 
rtrim($message_output,", ");
}
?>
__________________
xrvel is offline  
Old 12-03-2007, 08:06 AM THREAD STARTER               #7 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: Florida
Posts: 233
TeviH is an unknown quantity at this point
 



the checkboxes are not being sent as part of the data, and are really only used to make the form easier to use, from the user's perspective. Checking a checkbox just sets the quantity to "1" in the select box, but the information that is emailed is only from the select box; not the checkbox.

I don't know if any of this is making sense, so I will try to explain what I need, again: I would like to make some sort of declaration in the php that for any field with a value of "val0" do not email any information about that field. Not the name, and not the value.

Thanks!
__________________
www.headlinercreative.com
TeviH is offline  
Old 12-03-2007, 11:52 AM THREAD STARTER               #8 (permalink)
NamePros Regular
Join Date: Jul 2005
Location: Florida
Posts: 233
TeviH is an unknown quantity at this point
 



solved!

simple solution (isn't it always?):

instead of having the "0" value be "val0", I just left it blank... (thought I needed it there)
__________________
www.headlinercreative.com
TeviH is offline  
Old 12-03-2007, 10:21 PM   #9 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,615
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 





Originally Posted by TeviH
solved!
????: NamePros.com http://www.namepros.com/showthread.php?t=402479

simple solution (isn't it always?):

instead of having the "0" value be "val0", I just left it blank... (thought I needed it there)
You're right. If the select box has "0" value, it does not need to be appended in the mail
__________________
xrvel is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:25 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger