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 14/09/2007, 17h23   #1
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut no empty form fields after submitting form

Hello, a stupid question but...

page_A.php is a page with a form.
The user inserts text in four fields, then he clicks a submit button.
The data goes to page_B.php:
this page controls the data submitted, then echoes a message.
If there were problems with the submitted data the message says:
"a problem occurred with your data. Click here to come back to the
form" (page_A.php).
When the user comes back, he finds the fields white.

How can I do to show him what he submitted?

Thanks!

  Réponse avec citation
Vieux 14/09/2007, 17h39   #2
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)

>page_A.php is a page with a form.
>The user inserts text in four fields, then he clicks a submit button.
>The data goes to page_B.php:
>this page controls the data submitted, then echoes a message.
>If there were problems with the submitted data the message says:
>"a problem occurred with your data. Click here to come back to the
>form" (page_A.php).
>When the user comes back, he finds the fields white.


You don't need two pages. Let page_A show and handle the form
processing. Submit the form to the same page, check the values and show
the form again if there's an error.

To keep the form data while moving from one page to another you would
have to store the values in a session.

Micha
  Réponse avec citation
Vieux 14/09/2007, 17h47   #3
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

On Sep 14, 6:39 pm, Michael Fesser <neti...@gmx.de> wrote:
> To keep the form data while moving from one page to another you would
> have to store the values in a session.
>
> Micha




Ok, I'll use sessions, thanks!

  Réponse avec citation
Vieux 14/09/2007, 18h41   #4
Chuck Anderson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

pepper.gabriela@gmail.com wrote:
> Hello, a stupid question but...
>
> page_A.php is a page with a form.
> The user inserts text in four fields, then he clicks a submit button.
> The data goes to page_B.php:
> this page controls the data submitted, then echoes a message.
> If there were problems with the submitted data the message says:
> "a problem occurred with your data. Click here to come back to the
> form" (page_A.php).
> When the user comes back, he finds the fields white.
>
> How can I do to show him what he submitted?
>
> Thanks!
>
>


Create a form on page B. Copy all of the $_POST variables into hidden
fields with a submit button that says, "Go Back."

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
  Réponse avec citation
Vieux 14/09/2007, 20h05   #5
RageARC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

If you put them in the same page, it will be better for you. It will
ease the process.

[php]

if (isset($_POST['submit'])) {

# Process the form

if ($number_of_errors_in_the_form != 0) {

# Show the errors
# Display the Form Again.
# Example: print "<input type='text' name='fieldname' value='".
$_POST['fieldname']."' />";

} else {

# Tell the user everything went fine.

}

} else {

# Display the form.

}


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


>
> Create a form on page B. Copy all of the $_POST variables into hidden
> fields with a submit button that says, "Go Back."
>




hi chuck, it sounds interesting (I imagine form on page B should point
page A), but what if the user clicks the back button of his browser?

  Réponse avec citation
Vieux 15/09/2007, 20h11   #7
Chuck Anderson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

pepper.gabriela@gmail.com wrote:
>> Create a form on page B. Copy all of the $_POST variables into hidden
>> fields with a submit button that says, "Go Back."
>>
>>

>
>
>
> hi chuck, it sounds interesting (I imagine form on page B should point
> page A), but what if the user clicks the back button of his browser?
>
>


Yes, the form action on page B is to return to page A.

Clicking the Back button is fine. The browser loads the previous state
of page A, with the form fields still filled out.

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 Anderson • Boulder, CO
http://www.CycleTourist.com
The world is my country,
Science, my religion.
*****************************
  Réponse avec citation
Vieux 15/09/2007, 20h20   #8
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

Chuck Anderson wrote:
> pepper.gabriela@gmail.com wrote:
>>> Create a form on page B. Copy all of the $_POST variables into hidden
>>> fields with a submit button that says, "Go Back."
>>>
>>>

>>
>>
>>
>> hi chuck, it sounds interesting (I imagine form on page B should point
>> page A), but what if the user clicks the back button of his browser?
>>
>>

>
> Yes, the form action on page B is to return to page A.
>
> Clicking the Back button is fine. The browser loads the previous state
> of page A, with the form fields still filled out.
>


It will if you have the browser caching the page and haven't needed to
flush the cache. But you shouldn't depend on that behavior.

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


That's the best way to handle things.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
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
Vieux 16/09/2007, 18h32   #17
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

pepper.gabriela@gmail.com wrote:
>> 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.
>


No, instead you're just emulating the extract() function in your code.
Is that any smarter?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 16/09/2007, 18h38   #18
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

pepper.gabriela@gmail.com wrote:
>> 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?
>


Anyone. For instance, I could post a form to your site which has
anything I want on it. That's a very common way hackers get into systems.

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


And that means you'll never get it in the future? It's this very
thinking which leads to sites being hacked,

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


Always validate your data.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Vieux 17/09/2007, 00h20   #19
Chuck Anderson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

pepper.gabriela@gmail.com wrote:
> 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!
>


Sounds like you've got a handle on it.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
The world is my country,
Science, my religion. ... Huygens
*****************************
  Réponse avec citation
Vieux 17/09/2007, 00h23   #20
Sanders Kaufman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

> pepper.gabriela@gmail.com wrote:

>> Is there a handy way to know if there is 'something' in $_POST?



$bExists = is_set($_POST);
  Réponse avec citation
Vieux 17/09/2007, 16h28   #21
pepper.gabriela@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form


> Is that any smarter?


it isn't

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


> Anyone. For instance, I could post a form to your site which has
> anything I want on it. That's a very common way hackers get into systems.





But, sorry for my little experience, my forms only work if you logged
in (and you are a registered user and a session is active...). For
sure, I should understand how hackers do what they do...




> And that means you'll never get it in the future?




absolutely not



> Always validate your data.




ok, thanks

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


> $bExists = is_set($_POST);




isset?




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


> Sounds like you've got a handle on it.



:-)

  Réponse avec citation
Vieux 18/09/2007, 01h58   #25
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: no empty form fields after submitting form

pepper.gabriela@gmail.com wrote:
>> Anyone. For instance, I could post a form to your site which has
>> anything I want on it. That's a very common way hackers get into systems.

>
>
>
>
> But, sorry for my little experience, my forms only work if you logged
> in (and you are a registered user and a session is active...). For
> sure, I should understand how hackers do what they do...
>
>


And a hacker couldn't register and get a session active? Quite easy.

>
>
>> And that means you'll never get it in the future?

>
>
>
> absolutely not
>
>
>
>> Always validate your data.

>
>
>
> ok, thanks
>



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  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 17h41.


Édité par : vBulletin® version 3.7.3
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 ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,29068 seconds with 33 queries