473,699 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re-draw a form with user's input.

Jay
Hi everybody!

Please help me with this problem. I try to write code for server side
data validation. Initially, I have a html file called "form.html" which
just contains all the necessary fields for user to submit their contact
info (name, phone, email, address.....etc ...). All user's input will be
sent to "processForm.ph p" using POST. In processForm.php , I want to be
able to re-display the form in "form.html" with valid user's input and
error message on top of the form in case user enter invalid data.
Currently, a simple code that I could think of is the following:

<?php

if (!empty($_POST['submit']))
{
$isAllValid = false;
//Check for invalid data
//Code for checking data will be written here.

//Invalid data occur.
if(!$isAllValid )
{
include("form.h tml");

//set user's input in the form's fields. How to access
//form's field form here ?
}
}
else
{
echo "User not submit";
}

?>
My questions are:

1. Is there a way to access the form's fields in "form.html" to set
their values ? (given all the form's fields in form.html have unique
name)

2. If (1) is not doable, then how would I this in PHP ?

Thank you in advance !!

Jay Hana

Jul 17 '05 #1
6 2605
roll the form in with the validation

check for $_POST
- (process form data/validate, etc)
- (if valid add to DB, use HEADER to exit)
check for $_GET
- (create default/blank data or read in data from database)
HTML headings
HTML
- HTML form with PHP 'echo()' statements to put in data from above and
validation clues)

It is a bit more complex, but that is the basics of how to organize the
file.

larry

Jul 17 '05 #2
Jay
Dear Larry,

It's me again. Thanks for your quick response, but I am still stuck.
- (create default/blank data or read in data from database)
HTML headings
HTML
I don't want to add data to Database unless all data are valid.
- HTML form with PHP 'echo()' statements to put in data from above and
validation clues)


I don't want to re-write the HTML code for the form. That's why I use
include("form.h tml") in the processForm.php .

I think you misunderstood my question. I try to access form's field
within processForm.php page. For example,

Using document.getEle mentByID('eleme nt') to set the values of the
form's fields. May I do that ?

Thanks again,

Jay Hana

Jul 17 '05 #3
Jay wrote:


I don't want to add data to Database unless all data are valid.
That's standard.
- HTML form with PHP 'echo()' statements to put in data from above and
validation clues)

I don't want to re-write the HTML code for the form. That's why I use
include("form.h tml") in the processForm.php .


Then include the echo statements in the form itself. Just ensure the variables
are set to an empty string ('');

I think you misunderstood my question. I try to access form's field
within processForm.php page. For example,

Using document.getEle mentByID('eleme nt') to set the values of the
form's fields. May I do that ?

No you can't. PHP knows nothing about the HTML. Larry's response was correct
and accurate.
Thanks again,

Jay Hana

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 17 '05 #4
"Jay" <go*******@gmai l.com> kirjoitti
viestissä:11*** *************** ****@g14g2000cw a.googlegroups. com...
Hi everybody!

Please help me with this problem. I try to write code for server side
data validation. Initially, I have a html file called "form.html" which
just contains all the necessary fields for user to submit their contact
info (name, phone, email, address.....etc ...). All user's input will be
sent to "processForm.ph p" using POST. In processForm.php , I want to be
able to re-display the form in "form.html" with valid user's input and
error message on top of the form in case user enter invalid data.
Currently, a simple code that I could think of is the following:

<?php

if (!empty($_POST['submit']))
{
$isAllValid = false;
//Check for invalid data
//Code for checking data will be written here.

//Invalid data occur.
if(!$isAllValid )
{
include("form.h tml");

//set user's input in the form's fields. How to access
//form's field form here ?
}
}
else
{
echo "User not submit";
}

?>
My questions are:

1. Is there a way to access the form's fields in "form.html" to set
their values ? (given all the form's fields in form.html have unique
name)

2. If (1) is not doable, then how would I this in PHP ?

Simply set the value attribute of each field.

<input type="text" name="foo" value="<?= $_GET['foo'] ?>">

I'd say it works even though the file is called form.html, since you are
including the page, not passing it thru. In that case php tags should be
executed...

--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

et************* ***@5P4Mgmail.c om
Jul 17 '05 #5
I'm new to web programming but i think that you can make a function,
somthing like print_content($ error) which will be printed if you open
the page for the first time or if validation didn't pass(then you will
probably would like to pass #error variable)

Jul 17 '05 #6
Hello,

on 07/03/2005 03:23 PM SA*******@gmail .com said the following:
I'm new to web programming but i think that you can make a function,
somthing like print_content($ error) which will be printed if you open
the page for the first time or if validation didn't pass(then you will
probably would like to pass #error variable)


That is the way this forms validation and generation works. You post the
form to the same page where it is presented. If it was submitted the
class can validate the form values. If there is an invalid field, the
form may be presented again with information about the invalid fields.

http://www.phpclasses.org/formsgeneration
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #7

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

Similar topics

1
4306
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 be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6425
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 well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4096
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
4
18527
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 blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3699
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 sockets??
10
4216
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
3655
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 say that i like it to see mysql replaced by a real database (stored procedures etc.)
1
3633
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 NOT IN ( SELECT manufacturers_id FROM products )
3
3481
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 the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
1
3823
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 fazer?
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7745
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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 we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.