TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-11-2008, 01:45 PM   #1 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default How do you handle forms?

I'm curious how you handle submitted forms.

Like, do you just do static handling like $szName = $_POST['name']; or do you check all fields in a loop, or..?

And if you do, how do you send forms to your email-inbox?

Just curious :)


Oh, me myself.. I do it mostly the static way :)
maZtah is offline  
Reply With Quote
Old 03-11-2008, 01:50 PM   #2 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

I normally use a static method. For example I may have:

PHP Code:

$vName 
makeSafe($_POST['name']); 
One should never directly use submitted data. It should always be sanitised by a function, i.e. makeSafe in my example above.
Gareth is offline  
Reply With Quote
Old 03-11-2008, 01:54 PM   #3 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

Yeah, I always use mysql_real_escape_string when inserting submitted data into a database.

But my question was more how to process submitted forms, not how to secure them. ;)
maZtah is offline  
Reply With Quote
Old 03-11-2008, 04:27 PM   #4 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

PHP Code:
if ($_POST['submit'])
{
   
$name $_POST['name'];
    
$email $_POST['email'];
....

That's how I process them.
To send the thing to your email, just make a text, insert the post variables where needed and send that msg.
Check this code to how send mails: Gaming With PHP Blog Archive Send mails even to hotmail boxes
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
Old 03-11-2008, 06:47 PM   #5 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

You should read TalkPHP - Sending Emails with the Zend Framework for sending emails :)
Gareth is offline  
Reply With Quote
Old 03-11-2008, 07:31 PM   #6 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

PHP Code:
function processArray($post=array())
{
    
$misArrs true;
    foreach(
array_keys($post) as $key)
    {
        if(empty(
$post[$key]))
        {
            
$misArrs[] = $key;
        }
    }

    return 
$misArrs;

Haven't tried it but it should work fine and dandy.
__________________
"What everyone seems to forget is that while knowledge certainly is something - it's the implementation of knowledge that brings power" - Andres Galindo.
TlcAndres is offline  
Reply With Quote
Old 03-12-2008, 11:49 AM   #7 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

I played a abit with it, this is also a way I came up with:

PHP Code:
foreach ($_POST as $szKey => $szValue)
{
     
$aForm[$szKey] = secureInput($szValue);

Then you have all the fields in the $aForm array. So when you want to echo the fields just do echo $aForm['name'];. Easy as that.
maZtah is offline  
Reply With Quote
Old 03-12-2008, 12:20 PM   #8 (permalink)
The Contributor
 
abiko's Avatar
 
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
abiko is on a distinguished road
Default

I use Inspekt for all my superglobals :)
Just make a POST cage and assign values
PHP Code:
$post Inspekt::makePostCage();
$name $post->getRaw('post_name'); 
Easy as that
__________________
Back from sysadmins to the programmers.
Send a message via ICQ to abiko Send a message via MSN to abiko
abiko is offline  
Reply With Quote
Old 03-13-2008, 01:38 PM   #9 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

:)
PHP Code:
getPost("postname"); 
custom ;P
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 03-13-2008, 06:25 PM   #10 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

There is such a thing of reinventing the wheel you know.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 03-13-2008, 06:33 PM   #11 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

Nor, surely $_POST['postname']; is shorter than getPost("postname"); ?

Edit: Ahh, just thought; do you clean the input in the getPost function as well?
Gareth is offline  
Reply With Quote
Old 03-14-2008, 12:15 AM   #12 (permalink)
The Contributor
 
wiifanatic's Avatar
 
Join Date: Sep 2007
Posts: 29
Thanks: 8
wiifanatic is on a distinguished road
Default

PHP Code:
Forms::postDual('postname');
Forms::postHTML('postname');
Forms::postStrip('postname'); 
Yes, its a custom class.
wiifanatic is offline  
Reply With Quote
Old 03-14-2008, 03:45 AM   #13 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Quote:
Originally Posted by Gareth View Post
Nor, surely $_POST['postname']; is shorter than getPost("postname"); ?

Edit: Ahh, just thought; do you clean the input in the getPost function as well?
yep ;).., :P

Code:
function getPost($string)
{
	if( isset($_POST[ $string ]) )
	{
		if( empty( $_POST[ $string] ) ) return null;
		return stripslashes( htmlentities( $_POST[ $string ] , ENT_QUOTES ) );
	}
	return false;
}
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 03-14-2008, 10:13 PM   #14 (permalink)
WebDev'n Beer Drnkn' Fool
 
stewart's Avatar
 
Join Date: Dec 2007
Location: Denver, CO
Posts: 59
Thanks: 2
stewart is on a distinguished road
Default

Quote:
Originally Posted by maZtah View Post
I played a abit with it, this is also a way I came up with:

PHP Code:
foreach ($_POST as $szKey => $szValue)
{
     
$aForm[$szKey] = secureInput($szValue);

Then you have all the fields in the $aForm array. So when you want to echo the fields just do echo $aForm['name'];. Easy as that.
I was going to suggest that

Easiest way to go through and escape all of the input/post values.
__________________
stewart::howe
Web Developer & Programmer
CelerMedia.Com | iAmStewart.com | CelerLabs.com
Send a message via ICQ to stewart Send a message via AIM to stewart Send a message via MSN to stewart Send a message via Yahoo to stewart
stewart is offline  
Reply With Quote
Reply



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

Advanced Search
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

vB 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. The time now is 08:44 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design