Web Design Forum: Using the $_POST array - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using the $_POST array Rate Topic: -----

#1 User is offline   Stevo 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 469
  • Joined: 06-August 09
  • Reputation: 10
  • Gender:Male
  • Location:Birmingham, West Mids
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 07 August 2009 - 02:15 PM

Hi all, I have been using PHP for about 3 months so bare with me...

I'm building a site that uses lots of forms, thankfully they're all quite simple requests for email address/comments etc, at the moment I am getting the variables from the post array on each individual page like this:


<?php
$name=$_POST['Name']; 
$business=$_POST['Business'];
$email=$_POST['Email'];
?>


which works fine, but it isnt very efficient, especially if theres lots of variables. I want to create a generic form handler that i can call as an include, so use the POST array more like;

<?php
$userinput=$_POST ;
mycheckInputfunction($userinput);
echo "Thanks for your enquiry".$userinput['0'] ; ?>


Any help would be greatly appreciated
0

#2 User is offline   AJReading 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 182
  • Joined: 02-July 07
  • Reputation: 2
  • Gender:Male
  • Location:York
  • Experience:Advanced
  • Area of Expertise:Coder

Posted 08 August 2009 - 11:25 AM

You could loop through the POST array and assign a variable for each item in the array, this would probably not be a good idea though as people could potentially post anything they want and start messing with your variables.

Perhaps this would be better than manually assigning each variable.

$form = array('Name', 'Address', 'Postcode', 'Etc');
foreach ($form as $field) {
    if (isset($_POST[$field])) {
        $$field = $_POST[$field];
    }
}


This will create $Name, $Address, $Postcode etc for you and on line 4 where the variables are defined you can use any clean up functions you may want to perform on the user input.
1

#3 User is offline   Stevo 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 469
  • Joined: 06-August 09
  • Reputation: 10
  • Gender:Male
  • Location:Birmingham, West Mids
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 08 August 2009 - 01:47 PM

Brilliant,

Thanks AJ that sounds like what i'm after I'll give it a go :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users