PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > no empty form fields after submitting form
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
no empty form fields after submitting form

Réponse
 
LinkBack Outils de la discussion
Vieux 16/09/2007, 09h53   #9
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

> 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!

  Réponse avec citation
Vieux 16/09/2007, 11h29   #10
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form


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!



  Réponse avec citation
Vieux 16/09/2007, 11h47   #11
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

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
  Réponse avec citation
Vieux 16/09/2007, 11h56   #12
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form


> 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.

  Réponse avec citation
Vieux 16/09/2007, 12h43   #13
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

..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
  Réponse avec citation
Vieux 16/09/2007, 15h02   #14
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form


> 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.

  Réponse avec citation
Vieux 16/09/2007, 15h49   #15
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

..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
  Réponse avec citation
Vieux 16/09/2007, 16h08   #16
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form


> 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)


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h46.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19602 seconds with 16 queries