|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#9 |
|
Messages: n/a
Hébergeur: |
> I've even written a function that reads all of the elements in an array
> (e.g., $_POST) and creates hidden form fields for each one. It can even > handle multi-dimensional arrays (e.g., $_POST variables that are > themselves, an array). Chuck, this sound really interesting, simple and powerful too: at the moment, page B converts every key in a variable of the same name: foreach($_POST as $k => $v){ if(in_array($k,$required_keys)&&(trim($_POST[$k]!=''))){ ${$k}=$v; $count++; } } it would be quite easy to use this foreach to build my fields :-) Thanks! |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
Little problem in page A, now: I imagine I must verify if I have 'something' in $_POST (I get an Undefined Variable notice when I directly write: if($_POST[$k]!=''){ ${$k}=$v; } and I access this page for the first time, that is when for sure there is nothing in $_POST ) I tried if(array_key_exists(etc. but this way I must write code for any possible key... Is there a handy way to know if there is 'something' in $_POST? Thanks! |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Sun, 16 Sep 2007 12:29:20 +0200, <pepper.gabriela@gmail.com> wrote:
> Is there a handy way to know if there is 'something' in $_POST? > if(isset($_POST['something'])){/* do your thing */} -- Rik Wasmus |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
> if(isset($_POST['something'])){/* do your thing */} well, this presumes I must know what I'm receiving in page A... Anyway, the issue has been caused by the fact that I have not previously declared/initialized two variables, so when there's nothing in $_POST they simply don't exist. I partially solved declaring an undefined value before the $_POST verification code. |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
..oO(pepper.gabriela@gmail.com)
>Little problem in page A, now: > >I imagine I must verify if I have 'something' in $_POST if (!empty($_POST)) { ... } >(I get an Undefined Variable notice when I directly write: > > if($_POST[$k]!=''){ > ${$k}=$v; > } Even if the form was submitted and $_POST is not empty, you should check every value if it exists before you use it. You could write a little function for that. You could also have a look at the extract() function, if you want to convert the array into single variables. I don't consider that really necessary, but anyway. Micha |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
> Even if the form was submitted and $_POST is not empty, you should check > every value if it exists before you use it. why? I'm using them this way: if I receive the values I put them in the value field of the form, if I don't receive data, the field appears empty. > You could also have a look at the extract() function, if you want to > convert the array into single variables. I don't consider that really > necessary, but anyway. I considered not using it because the PHP manual says it is not a good idea for $_GET, $_POST, etc. |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
..oO(pepper.gabriela@gmail.com)
>> Even if the form was submitted and $_POST is not empty, you should check >> every value if it exists before you use it. > >why? You can't be sure that you'll get all the values from the form you expect. Every data coming in from the client (POST, GET, ) can be incomplete or manipulated. >I'm using them this way: if I receive the values I put them in the >value field of the form, if I don't receive data, the field appears >empty. You just have to make sure that missing values don't lead to notices or unexpected behaviour in your code. >> You could also have a look at the extract() function, if you want to >> convert the array into single variables. I don't consider that really >> necessary, but anyway. > >I considered not using it because the PHP manual says it is not a good >idea for $_GET, $_POST, etc. Currently you're doing nearly the same. Micha |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
> You can't be sure that you'll get all the values from the form you > expect. Every data coming in from the client (POST, GET, ) can be > incomplete or manipulated. i'm in the classical little/medium site backend area sending data thorugh $_POST: what could cause incompleteness? Who could manipulate my data? > You just have to make sure that missing values don't lead to notices or > unexpected behaviour in your code. it is what I try to do and I'm not receiving any unexpected behavior at the moment :-) > >I considered not using it because the PHP manual says it is not a good > >idea for $_GET, $_POST, etc. > > Currently you're doing nearly the same. well, it's true... I couldn't find a better way, since I can't change the overall structure (so I can't but send data from A to B and viceversa) |
|
![]() |
| Outils de la discussion | |
|
|