473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.php" 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.html");

//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 2581
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.html") 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.getElementByID('element') 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.html") 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.getElementByID('element') 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*******@attglobal.net
==================
Jul 17 '05 #4
"Jay" <go*******@gmail.com> kirjoitti
viestissä:11**********************@g14g2000cwa.goo glegroups.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.php" 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.html");

//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.com
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
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
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...
1
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...
4
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
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
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
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
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
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
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.