Jump to content

[SOLVED] Checking the $_POST


maliary

Recommended Posts

 

 

I have the following when I print out $_POST

 

Array ( [submit] => Submit [se1] => qqqq [se2] => wwwww [se3] => [se4] => [se5] => [se6] => [se7] => [sid] => 82ea244a6fd9125be1a200a3d211d370 [lang] => en [station] => [dept] => [dept_nr] => 25 [pn] => 45272 [batch_nr] => 955071 [edit] => 0 [target] => admin [subtarget] => baclabor [tracker] => 32 [noresize] => [user_origin] => lab [status] => pending [mode] => save [formtitle] => Bacteriological Laboratory [entry_date] => )

 

I would like to filter it out and leave only the one's with values e.g. remove [se4] =>

In that case I'd probably use

 

foreach ($_POST as $key => $value)
{
   if (empty($v))
   {
      continue;
   }
   else
   {
      $posted[$key] = $v
   }
}

 

You should have an array ($posted) that just contains the relevant fields.

 

Regards

Huggie

 

 

I have the following when I print out $_POST

 

Array ( [submit] => Submit [se1] => qqqq [se2] => wwwww [se3] => [se4] => [se5] => [se6] => [se7] => [sid] => 82ea244a6fd9125be1a200a3d211d370 [lang] => en [station] => [dept] => [dept_nr] => 25 [pn] => 45272 [batch_nr] => 955071 [edit] => 0 [target] => admin [subtarget] => baclabor [tracker] => 32 [noresize] => [user_origin] => lab [status] => pending [mode] => save [formtitle] => Bacteriological Laboratory [entry_date] => )

 

I would like to filter it out and leave only the one's with values e.g. remove [se4] => (This is done! Thanks for the code guys)

 

Then have a string like this

 
sel=jjjjjjj&=se2=hhhhhhhhhh&

 

showing the index and value combination only for those indexes that start with 'se' e.g.[se1]

if its blank like this [se4] => don't display it. it should be displayed only when its this way [se4] => www

the array element has a value.

 

 

The solution :

 

<?php

$values = array();

if(count($_POST)){

  foreach($_POST AS $k=>$v){

      if(isset($v) && strlen(trim($v)){

        $values[$k] = trim($v);

          if (k{o} == 's')

                    {

                if (k{1} == 'e')

                      {

                          $res = $res. $k .'='.$v.'&=';

                          }

                              }

 

       

      }

 

 

Jesirose, Thanks a Million Times !!!!!!!!!!!!!!!!!!

 

 

  }

  print_r($values);

}else{

  print 'no posted';

}

?>

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.