473,508 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
Jul 17 '05 #1
5 2109
php newbie <ne**********@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.
Jul 17 '05 #2
ilo
ne**********@yahoo.com (php newbie) wrote in
news:12**************************@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
Jul 17 '05 #3

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" <ne**********@yahoo.com> wrote in message
news:12**************************@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?

Jul 17 '05 #4
The super lazy way to do it

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

Uzytkownik "php newbie" <ne**********@yahoo.com> napisal w wiadomosci
news:12**************************@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?

Jul 17 '05 #5
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 ?>">
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4267
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
6410
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
4
18514
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
3687
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
4196
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
3645
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
3622
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
3468
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
1
13616
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
1
3815
by: Clarice Almeida Hughes | last post by:
tenho um index onde tenho o link pro arq css, como sao visualizados pelo include todas as paginas aderem ao css linkado no index. so q eu preciso de alguns links com outras cores no css, o q devo...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.