Re-populating a form if errors

This is a discussion on Re-populating a form if errors within the PHP Language forums, part of the PHP Programming Forums category; Hello, I am learning php. I have created a simple Web page with a form. After receing the POST request, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2004
php newbie
 
Posts: n/a
Default Re-populating a form if errors

Hello,

I am learning php. I have created a simple Web page with a form.
After receing the POST request, I do some error checking. In case of
errors, I would like to re-post the page, but with the current values
for each field.

I have organized my files like this:
1) Webpage with the form (all in html, form action points to a php
file)
2) php file that receives the request.

Is there a simple way to accomplish this?
Reply With Quote
  #2 (permalink)  
Old 01-17-2004
steven mestdagh
 
Posts: n/a
Default Re: Re-populating a form if errors

php newbie <newtophp2000@yahoo.com> wrote:
> Hello,
>
> I am learning php. I have created a simple Web page with a form.
> After receing the POST request, I do some error checking. In case of
> errors, I would like to re-post the page, but with the current values
> for each field.
>
> I have organized my files like this:
> 1) Webpage with the form (all in html, form action points to a php
> file)
> 2) php file that receives the request.
>
> Is there a simple way to accomplish this?


it is simpler to put everything in one php file and checking
whether the $_POST array is not empty.

you can keep your values with a construction like this:

<input name="author" <?php if (isset($_POST['author']))
{echo " value=$_POST['author']";}?>>


steven.
Reply With Quote
  #3 (permalink)  
Old 01-17-2004
ilo
 
Posts: n/a
Default Re: Re-populating a form if errors

newtophp2000@yahoo.com (php newbie) wrote in
news:124f428e.0401171143.59aa3f81@posting.google.c om:

> Hello,
>
> I am learning php. I have created a simple Web page with a form.
> After receing the POST request, I do some error checking. In case of
> errors, I would like to re-post the page, but with the current values
> for each field.
>
> I have organized my files like this:
> 1) Webpage with the form (all in html, form action points to a php
> file)
> 2) php file that receives the request.
>
> Is there a simple way to accomplish this?
>


when you reload the page in the input there is the option value so you
would do:

<input ..... value=<? echo $test; ?> />

hope this is right :p

ilo
Reply With Quote
  #4 (permalink)  
Old 01-18-2004
The Plankmeister
 
Posts: n/a
Default Re: Re-populating a form if errors


Do it all in one file, for example parse_my_form.php:


<?php

$str_name = !empty($_POST['name']) ? $_POST['name'] : "";
$str_age = !empty($_POST['age']) ? $_POST['age'] : "";
$str_error = "";

if($str_name == "" or $str_age == "")
$str_error = "<p>Error parsing form</p>";
else
header("Location: http://mywebsite.com/form_submission_ok.php");
?>

<html>
<head>
<title>Fill in the boxes!</title>
</head>

<body>

<?php echo $str_error ?>

<form name="form1" action="parse_my_form.php" method="post">

<input name="name" type="text">
<input name="age" type="text">
<input type="submit">

</form>


</body>
</html>






"php newbie" <newtophp2000@yahoo.com> wrote in message
news:124f428e.0401171143.59aa3f81@posting.google.c om...
> Hello,
>
> I am learning php. I have created a simple Web page with a form.
> After receing the POST request, I do some error checking. In case of
> errors, I would like to re-post the page, but with the current values
> for each field.
>
> I have organized my files like this:
> 1) Webpage with the form (all in html, form action points to a php
> file)
> 2) php file that receives the request.
>
> Is there a simple way to accomplish this?



Reply With Quote
  #5 (permalink)  
Old 01-18-2004
Chung Leong
 
Posts: n/a
Default Re: Re-populating a form if errors

The super lazy way to do it

header("HTTP/1.0 204 No Content");
exit();

Uzytkownik "php newbie" <newtophp2000@yahoo.com> napisal w wiadomosci
news:124f428e.0401171143.59aa3f81@posting.google.c om...
> Hello,
>
> I am learning php. I have created a simple Web page with a form.
> After receing the POST request, I do some error checking. In case of
> errors, I would like to re-post the page, but with the current values
> for each field.
>
> I have organized my files like this:
> 1) Webpage with the form (all in html, form action points to a php
> file)
> 2) php file that receives the request.
>
> Is there a simple way to accomplish this?



Reply With Quote
  #6 (permalink)  
Old 01-18-2004
The Plankmeister
 
Posts: n/a
Default Re: Re-populating a form if errors

Ooops... change these lines:

<input name="name" type="text">
<input name="age" type="text">

To this:

<input name="name" type="text" value="<?php echo $str_name ?>">
<input name="age" type="text" value="<?php echo $str_age ?>">


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0