Jump to content

Why "unset" stuff from form ?


scanreg

Recommended Posts

I'm trying to understand the rationale for unsetting things in the following function :

 

   function _process_form($method) {        
        if(function_exists("process_form")) {
            $data = $method;
            foreach($data as $key=>$val) {                
                if(preg_match("/(submit|required)|(_desc$)/i", $key) == 1)
                    unset($data[$key]);
            }
            process_form($data);
        }
    }

 

What is the unsetting actually doing?

 

Why do it?

 

I've seen this kind of thing in many form scripts, just trying to figure out why.

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/206171-why-unset-stuff-from-form/
Share on other sites

Hi

 

Appears to loop though an array which is a copy of passed fields (presume the $_GET, $_POST or $_REQUEST arrays), and wipes all those where the key matches a particular pattern. Any that are left are then properly processed.

 

Just appears to be an easy way to mark (ie, delete them rather than flagging them) which fields are not to be process.

 

All the best

 

Keith

Hi

 

Appears to loop though an array which is a copy of passed fields (presume the $_GET, $_POST or $_REQUEST arrays), and wipes all those where the key matches a particular pattern. Any that are left are then properly processed.

 

Just appears to be an easy way to mark (ie, delete them rather than flagging them) which fields are not to be process.

 

All the best

 

Keith

 

Thanks Keith

 

Yes, I thought so, but it's in the preg_match that I guess I'm confused.

 

Isn't the preg_match statement matching all those that should be accepted?

 

In other words, if you want to unset all those that don't match, then shouldn't the preg_match be like this (!preg_match - see below):

 

            foreach($data as $key=>$val) {             

                if(!preg_match("/(submit|required)|(_desc$)/i", $key) == 1)

                    unset($data[$key]);

 

"If it doesn't match one of these patterns, then unset it"

 

In other words, if it does match the desired pattern, then you do want it, otherwise unset it ??

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.