473,322 Members | 1,911 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,322 software developers and data experts.

php form display function

I hope I can state this clearly enough.

I am redoing some of my html(php) forms. I'm trying to break things
into three functions on a self processing php page:
1) show the form (and populate fields if there were errors)
2) validate form data
3) process form data

2 and 3 are no problem, but 1 is. The page with the form displayed
should validate as html 4.01 strict (actually all iterations of the page
need to validate). The actual page is a mix of php and html (popping in
and out of php w/ '<?PHP' and '?>' as needed, so that I can see what
the page layout will be. To validate I have been serving page.php
saving it as page.html and validating that. I'm sure there is a better
way to do this.

To keep the code logic and markup 'separate' and easier to read, I have
been using include files of valid html (i.e. a div containing the
form,with my pop-in's of php, or a div containing the 'thank you, we'll
get back to you'). like this:

<?php
if (array_key_exists('_submit_check',$_POST)) {
if ($form_errors = validate_form()) {
//the form has errors or was submitted by another source
show_form($form_errors);
} else {
// The submitted data is valid, so process it
process_form();
}
} else { // The form wasn't submitted, so display
include('./incForm.php');
}
?>

Is there a good way to show the form, any errors and re-populating all
the form fields? I thought about using session variables (seeding the
form and storing values until all errors have been resolved), but am not
sure that's the way to go.



Apr 7 '08 #1
1 3925
On Apr 7, 10:49 am, William Gill <nore...@example.comwrote:
I hope I can state this clearly enough.

I am redoing some of my html(php) forms. I'm trying to break things
into three functions on a self processing php page:
1) show the form (and populate fields if there were errors)
2) validate form data
3) process form data

2 and 3 are no problem, but 1 is. The page with the form displayed
should validate as html 4.01 strict (actually all iterations of the page
need to validate). The actual page is a mix of php and html (popping in
and out of php w/ '<?PHP' and '?>' as needed, so that I can see what
the page layout will be. To validate I have been serving page.php
saving it as page.html and validating that. I'm sure there is a better
way to do this.

To keep the code logic and markup 'separate' and easier to read, I have
been using include files of valid html (i.e. a div containing the
form,with my pop-in's of php, or a div containing the 'thank you, we'll
get back to you'). like this:

<?php
if (array_key_exists('_submit_check',$_POST)) {
if ($form_errors = validate_form()) {
//the form has errors or was submitted by another source
show_form($form_errors);
} else {
// The submitted data is valid, so process it
process_form();
}} else { // The form wasn't submitted, so display

include('./incForm.php');}

?>

Is there a good way to show the form, any errors and re-populating all
the form fields? I thought about using session variables (seeding the
form and storing values until all errors have been resolved), but am not
sure that's the way to go.
I would do two things
1. Write the form with a conditional statement next to each input (if
$error then display error message)
2. Write each element like <input type="text" id="fname" value="<?=
$_POST['fname'] />. The first time somebody comes to the form there
will be nothing in POST, so the form will be blank. Subsequent
attempts will carry forward the data they've already entered.
Apr 7 '08 #2

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

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
5
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
7
by: Terry | last post by:
I have a Mainform with a Statusbar. When opening another form or doing some processing I want to display info in the Statusbar of the Mainform. I have read a lot of articles on this & have come up...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
4
by: Regnab | last post by:
I've got a form - "frmLookup" (with a subform) that works very happily on its own. The form has a list box, which when updated requeries the subform to display the appropriate results. The...
2
by: plumba | last post by:
Ok, another problem... A bit querky this one.. My form calls an onsubmit function to check fields for completion (validation check). Here is a breakdown version of the form: <html>...
5
by: plumba | last post by:
Hi all I have a form (see below), which for some reason has decided to stop functioning all together. It just does not call up the function. It is called up in the opening <form> tag but...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
0
rnd me
by: rnd me | last post by:
Purpose: Allows you to create "presets" for text form inputs. "Lightweight and simple to setup, it adds a lot of convenience for ~1kb of code." Only one function, two parameters: First...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.