Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Using the $_POST array

Featured Replies

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

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.

  • Author

Brilliant,

 

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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.