Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2007-10-15, 02:09 AM
Junior Member
 
Join Date: Oct 2007
Posts: 3
random1739 is on a distinguished road
Default PHP contact form - Rejecting invalid entries

Hi everyone, I've used Smarty (Smarty : Template Engine) to make a PHP-powered Contact page for a web site.

At the moment it works fine and displays fine, but I'd like to redirect the user to an error page if they forget to include their return email address.

Here's the complete code from the PHP page:

PHP Code:
<?php

require_once('libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->compile_check true;
$smarty->debugging false;

if (isset(
$_POST['action']) && $_POST['action'] == 'Submit request')
{
    
$body '';
    
$body .= 'How did you hear about Dive Adventures? ' $_POST['heard'] . "\n";
    
$body .= "\n";
    
$body .= '* Your adventure' "\n";
    
$body .= 'Which destination are you interested in? ' $_POST['holiday'] . "\n";
    
$body .= 'When do you intend to travel? ' $_POST['month'] . ' ' $_POST['year'] . "\n";
    
$body .= 'What type of diving do you enjoy doing? ' $_POST['diving_type'] . "\n";
    
$body .= 'Number of guests: ' "\n";
    
$body .= 'Adults: ' $_POST['adults'] . ' (' $_POST['adult_divers'] . ' are divers)' "\n";
    
$body .= 'Children: ' $_POST['children'] . ' (' $_POST['child_divers'] . ' are divers)' "\n";
    
$body .= 'Infants: ' $_POST['infants'] . ' (' $_POST['infant_divers'] . ' are divers)' "\n";
    
$body .= 'Comments: ' "\n";
    
$body .= $_POST['comments'] . '.' "\n";
    
$body .= "\n";
    
$body .= '* Your details' "\n";
    
$body .= 'Name ' $_POST['name'] . "\n";
    
$body .= 'Email ' $_POST['email'] . "\n";
    
$body .= 'Address ' $_POST['address'] . "\n";
    
$body .= 'City ' $_POST['city']  . "\n";
    
$body .= 'Postcode ' $_POST['postcode']  . "\n";
    
$body .= 'State ' $_POST['state']  . "\n";
    
$body .= 'Country ' $_POST['country']  . "\n";
    
$body .= 'Contact by telephone? ' . ($_POST['contactbytelephone'] ? 'Yes' 'No' ) . "\n";
    
$body .= 'Telephone number ' $_POST['phone'] . "\n";
    
$body .= 'Monthly newsletter? ' . ($_POST['receivenewsletter'] ? 'Yes' 'No' ) . "\n";
    
//echo str_replace("\n", '<br>', $body);

    
$to 'divesydney@optusnet.com.au';
    
$from "diveadventures <sydney@diveadventures.com.au>";
    
$subject "Holiday information - From www.diveadventures.com.au";
    
$headers "From: $from";
    
mail($to$subject$body$headers);

    
$smarty->assign('submit'1);
    
}


smarty_constants(&$smarty);

$smarty->display('head.tpl');
$smarty->display('contact.tpl');
$smarty->display('tail.tpl');


function 
smarty_constants(&$smarty)
{
    
$HEARDS = array (
        
'The Internet' => 'The Internet',
        
'Word of Mouth' => 'Word of Mouth',
        
'Business reference' => 'Business reference',
        
'Advertisement' => 'Advertisement',
        
'Dive magazine' => 'Dive magazine',
        
'Other' => 'Other'
    
);

    
$smarty->assign('heards'$HEARDS);


    
$HOLIDAYS = array (
        
'Australia / Great Barrier Reef' => 'Australia / Great Barrier Reef',
        
'Cocos (Keeling) / Christmas Islands' => 'Cocos (Keeling) / Christmas Islands',
        
'Cook Islands' => 'Cook Islands',
        
'East Timor' => 'East Timor',
        
'Fiji' => 'Fiji',
        
'Indonesia' => 'Indonesia',
        
'Liveaboards' => 'Liveaboards',
        
'Malaysia' => 'Malaysia',
        
'Maldives' => 'Maldives',
        
'Marshall Islands' => 'Marshall Islands',
        
'Micronesia' => 'Micronesia',
        
'Niue' => 'Niue',
        
'Papua New Guinea' => 'Papua New Guinea',
        
'Philippines' => 'Philippines',
        
'Red Sea / Egypt' => 'Red Sea / Egypt',
        
'Solomon Islands' => 'Solomon Islands',
        
'Tahiti' => 'Tahiti',        
        
'Tonga' => 'Tonga',        
        
'Vanuatu' => 'Vanuatu',        
        
'Western Samoa' => 'Western Samoa',        
        
'Other (Refer to comments)' => 'Other (Refer to comments)'
        
    
);

    
$smarty->assign('holidays'$HOLIDAYS);


    
$DIVING_TYPES = array (
        
'Wreck' => 'Wreck',
        
'Cave' => 'Cave',
        
'Reef' => 'Reef',
        
'Wall' => 'Wall',
        
'Temperate Water' => 'Temperate Water',
        
'Tropical' => 'Tropical',
        
'Deep' => 'Deep',
        
'Drift' => 'Drift',
        
'Exploratory' => 'Exploratory',
        
'Live-aboards' => 'Live-aboards',
        
'Technical Diving' => 'Technical Diving',
        
'Mixed Gases' => 'Mixed Gases'
    
);

    
$smarty->assign('diving_types'$DIVING_TYPES);


    
$MONTHS = array (
        
'January' => 'January',
        
'February' => 'February',
        
'March' => 'March',
        
'April' => 'April',
        
'May' => 'May',
        
'June' => 'June',
        
'July' => 'July',
        
'August' => 'August',
        
'September' => 'September',
        
'October' => 'October',
        
'November' => 'November',
        
'December' => 'December'
    
);

    
$smarty->assign('months'$MONTHS);

    
$YEARS = array (
        
'2007' => '2007',
        
'2008' => '2008',
        
'2009' => '2009',
        
'2010' => '2010',
    );

    
$smarty->assign('years'$YEARS);

    return;
}

?>
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2007-10-16, 04:32 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

The best thing to do is use JavaScript to do it on the orginal page, so they dont even have to wait for a new load.

Here is a decent article on how to do it:

JavaScript Form Validation

If you get lost, post back and I will give you a specific example of a slightly different method I use within my apps.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2007-10-21, 09:04 PM
Junior Member
 
Join Date: Oct 2007
Posts: 3
random1739 is on a distinguished road
Default

I'm not all that familiar with using javascript.

When I tried to insert that code in the html template page (on which the PHP script is run from), it failed and gave me an error message for the line:
"with (field)"

I'll give things another go when I get the chance, but the Smarty template system makes things a little more confusing.

Theres a header page, a footer page, a template page and a PHP page. All needed to display and run the contact.php page which visitors see.
Reply With Quote
  #4 (permalink)  
Old 2007-10-24, 03:25 AM
Junior Member
 
Join Date: Oct 2007
Location: India-Delhi
Posts: 1
Megrisoft is on a distinguished road
Thumbs up Thanks........

Hello,

I will say that instead of directing to error page, you should use java validations for user input, you can see and find and nice code from dynamic drive website!
__________________
PHP and MYSQL Expert Programmer
PHP/Mysql development outsourcing company
Indian PHP MYSQL Developer

Last edited by Megrisoft; 2007-10-24 at 05:36 AM.
Reply With Quote
  #5 (permalink)  
Old 2007-11-18, 05:22 PM
Junior Member
 
Join Date: Oct 2007
Posts: 3
random1739 is on a distinguished road
Default

Quote:
Originally Posted by Megrisoft View Post
Hello,

I will say that instead of directing to error page, you should use java validations for user input, you can see and find and nice code from dynamic drive website!
Sorry for bumping an old thread, but I'm still in need of help.

Can you provide me with a link to the right stuff on the dynamic drive website, I can't seem to find the one you were referring to.

I was hoping for a simple 1 or 2 line addition to the PHP code in the page I have, but whatever is simplest.

I need to have the form NOT submit unless the user has entered a valid email address and telephone number
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:58 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.