hosted by liquidweb

Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : How Can I Do This?

Forum Jump

How Can I Do This?

Reply Post New Thread In Programming Discussion Subscription
Send news tip View All Posts Thread Tools Search this Thread Display Modes
Junior Guru
Join Date: Oct 2001
Posts: 193

How Can I Do This?

I added an error checking section in my form script and I was wondering if somone can help me out. Instead of doing this:

PHP Code:
// define fields
$fields = array ('field1''field2''field3');

// print the error
if (empty($_POST['fields'])) {

I would like to make automatically pull the name of each variable and add the _error to it like:


This way I won't have to make another line for each field.

Any help would be greatly appreciated.



Sponsored Links
Join Date: May 2002
Posts: 6
did a little searching on

so to do what you want would be

PHP Code:
foreach ($HTTP_POST_VARS AS $pram=>$value){    
define ($value "_error""Error Text");

Will treat the values as strings and say you had a variable named $name, your error version should be name_error without the $


if (empty($_POST['fields'])) {
$fields = $_POST['fields'];
define ($fields[$i] . "_error", "Error Text");
//All done

to test the values....(you can also use the for next here as well
if ( defined('something_error') && something_error ) print(something_error);

you may also use a case insensative feature by inserting
, TRUE);
at the end of
define ($fields[$i] . "_error", "Error Text", TRUE);

Last edited by turnball; 09-20-2002 at 02:47 AM.

Related posts from
Title Type Date Posted

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Log in with your username and password

Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Web Hosting News:
WHT Membership
WHT Membership



Welcome to

Create your username to jump into the discussion! is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.

(4 digit year)

Already a member?