Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-18-2010, 03:54 PM handling large forms
Extreme Talker

Posts: 173
Trades: 0
Just getting into this form creation stuff, and I find it seems that I am creating large areas of code to handle all form fields. As shown below. Is there are better way to do this?

PHP Code:
$project_id=NULL;
$project=NULL;
$project_desc=NULL;
$work_flow=NULL;
$network_number=NULL;
$documentum=NULL;
$pdit=NULL;
$xfer_service=NULL;
$service_request=NULL;
$product_line=NULL;
$wt_accpet=NULL;
$wt_ship=NULL;
$aoa=NULL;
$reporting_currency=NULL;
$inco_term=NULL;
$inco_place=NULL;
$rdd=NULL;
$float=NULL;
$transit_time=NULL;
$ship_date=NULL;
$st_cd=NULL;
$st_courier=NULL;
$st_email=NULL;
$st_ftp=NULL;
$review_period=NULL;
$submit_office=NULL;
$document_level=NULL;
$margin_level=NULL;
$contigency=NULL;
$financials=NULL;
$owner=NULL;
$customer=NULL;
$consultant=NULL;
//Update Project details
if(!empty($_POST['project_id'])){
           
$project_id=sanitize_string($_POST['project_id']);
 if(isset(
$_POST['project']))   $project=sanitize_string($_POST['project']);
 if(isset(
$_POST['project_desc']))  $project_desc=sanitize_string($_POST['project_desc']);
 if(isset(
$_POST['work_flow']))   $work_flow=sanitize_string($_POST['work_flow']);
 if(isset(
$_POST['network_number']))  $network_number=sanitize_string($_POST['network_number']);
 if(isset(
$_POST['documentum']))   $documentum=sanitize_string($_POST['documentum']);
 if(isset(
$_POST['pdit']))    $pdit=sanitize_string($_POST['pdit']);
 if(isset(
$_POST['xfer_sevice']))  $xfer_sevice=sanitize_string($_POST['xfer_sevice']);
 if(isset(
$_POST['service_request'])) $service_request=sanitize_string($_POST['service_request']);
 if(isset(
$_POST['product_line']))  $product_line=sanitize_string($_POST['product_line']);
 if(isset(
$_POST['wt_accpet']))   $wt_accpet=sanitize_string($_POST['wt_accpet']);
 if(isset(
$_POST['wt_ship']))   $wt_ship=sanitize_string($_POST['wt_ship']);
 if(isset(
$_POST['aoa']))    $aoa=sanitize_string($_POST['aoa']);
 if(isset(
$_POST['reporting_currency'])) $reporting_currency=sanitize_string($_POST['reporting_currency']);
 if(isset(
$_POST['inco_term']))   $inco_term=sanitize_string($_POST['inco_term']);
 if(isset(
$_POST['inco_place']))   $inco_place=sanitize_string($_POST['inco_place']);
 if(isset(
$_POST['rdd']))    $rdd=sanitize_string($_POST['rdd']);
 if(isset(
$_POST['float']))    $float=sanitize_string($_POST['float']);
 if(isset(
$_POST['transit_time']))  $transit_time=sanitize_string($_POST['transit_time']);
 if(isset(
$_POST['ship_date']))   $ship_date=sanitize_string($_POST['ship_date']);
 if(isset(
$_POST['st_cd']))    $st_cd=sanitize_string($_POST['st_cd']);
 if(isset(
$_POST['st_courier']))   $st_courier=sanitize_string($_POST['st_courier']);
 if(isset(
$_POST['st_email']))   $st_email=sanitize_string($_POST['st_email']);
 if(isset(
$_POST['st_ftp']))    $st_ftp=sanitize_string($_POST['st_ftp']);
 if(isset(
$_POST['review_period']))  $review_period=sanitize_string($_POST['review_period']);
 if(isset(
$_POST['submit_office']))  $submit_office=sanitize_string($_POST['submit_office']);
 if(isset(
$_POST['document_level']))  $document_level=sanitize_string($_POST['document_level']);
 if(isset(
$_POST['margin_level']))  $margin_level=sanitize_string($_POST['margin_level']);
 if(isset(
$_POST['contigency']))   $contigency=sanitize_string($_POST['contigency']);
 if(isset(
$_POST['financials']))   $financials=sanitize_string($_POST['financials']);
 if(isset(
$_POST['owner']))    $owner=sanitize_string($_POST['owner']);
 if(isset(
$_POST['consultant']))   $consultant=sanitize_string($_POST['consultant']);
 
$sql='UPDATE tbl_staff '.
  
'SET first_name='.$first_name.', surname='.$surname.', sso='.$sso.', alias='.$alias.', '.
  
'    email='.$email.', phone='.$phone_office.', ext='.$ext.', cell='.$phone_cell.', '.
  
'    title='.$position.', manager_sso='.$manager_sso.
  
' WHERE staff_id='.$staff_id;
 
$resultquery($sql);
 
 echo 
'<head>'.
   
'<META HTTP-EQUIV="REFRESH" CONTENT="3;URL=display_project_details.php">'.
   
'Project details updated. 
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-18-2010, 05:35 PM Re: handling large forms
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
perhaps:

PHP Code:
foreach ($_POST as &$field)
    {
     
$field=sanitize_string($field);
    } 
By using &$field instead of just $field - you reference each item in the $_POST array directly and apply the procedure to it, rather than a copy of it.

Then you could simply access all the variables as $_POST['fieldname'] in your SQL
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.

HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Old 08-18-2010, 05:38 PM Re: handling large forms
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
Perhaps also
PHP Code:
$field_list=array('field1','field2','field3');

foreach (
$field_list as $field_name)
    {
     if (!isset(
$_POST[$field_name]))
          {
             
$_POST[$field_name]=NULL;
          }
    } 
This will set any missing fields to NULL
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.

HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Old 08-18-2010, 08:46 PM Re: handling large forms
Extreme Talker

Posts: 173
Trades: 0
Love the ideas, thanks.
dgkindy is offline
Reply With Quote
View Public Profile
 
Old 08-19-2010, 01:07 AM Re: handling large forms
Junior Talker

Posts: 1
Name: Tushi
Trades: 0
Hello!!!!!

thanks for your information!!!!!!!!
tushi2010 is offline
Reply With Quote
View Public Profile
 
Old 08-19-2010, 09:38 PM Re: handling large forms
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
You're quite welcome - if it was useful, please feel free to add to my talkupation ;-)
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.

HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Old 08-23-2010, 11:55 PM Re: handling large forms
Novice Talker

Posts: 12
Trades: 0
thanks for your information!!!!!!!!Good idea !
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
royang is offline
Reply With Quote
View Public Profile
 
Old 08-24-2010, 11:10 PM Re: handling large forms
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by HandCoder View Post
perhaps:

PHP Code:
foreach ($_POST as &$field)
    {
     
$field=sanitize_string($field);
    } 
By using &$field instead of just $field - you reference each item in the $_POST array directly and apply the procedure to it, rather than a copy of it.
Interesting, I always thought foreach worked on a copy of the array only. I found out that the references only work in PHP >= 5


Quote:
Originally Posted by HandCoder View Post
Perhaps also
PHP Code:
$field_list=array('field1','field2','field3');
 
foreach (
$field_list as $field_name)
    {
     if (!isset(
$_POST[$field_name]))
          {
             
$_POST[$field_name]=NULL;
          }
    } 
This will set any missing fields to NULL
Note: Using a NULL value will evaluate as not set.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to handling large forms
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27703 seconds with 12 queries