473,626 Members | 3,936 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_exis ts('_submit_che ck',$_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 3942
On Apr 7, 10:49 am, William Gill <nore...@exampl e.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_exis ts('_submit_che ck',$_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
40703
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 style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person filling out the form is switching from page to page...without the overhead of extra hits on the server,...
5
5246
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 box that is populated with the code =subfrm_media_review_sec_party.Form!first_name & " " & subfrm_media_review_sec_party.Form!last_name It works except that when I flip through the names it populates the parent form with the name of what ever...
11
18830
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 they are too big and wind up covering up some of the fields on the main form. Is there any good code out there that works in a similar fashion that will also either a) stretch the form width wise on widescreens or b), rely on height rather than...
7
3380
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 with the code below. It seems to work(!!!) in that when coding the second form I can see the DisplayStatusMsg of the main form. During debug the code runs through & seemingly executes the call without error. But!...The message is not displayed....
4
2707
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 multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
4
2080
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 problem is that for the final user interface, I had planned to use a "frmDisplay" form which had a number of menu items and then depending on what the user selected, it would display the appropraite form in a subform beneath the menu items. I did this...
2
1731
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> <script> function toggle_display() { var form = document.getElementById('hidesubmit');
5
2537
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 fails.... Any ideas??? <html> <head><title>New Details</title> </head> <center> <H2><IMG SRC="$(path)smlogo.gif"><br>
0
3376
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 within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
0
4480
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 argument is the element to upgrade. you can specify the input's name, id or the input itself. you can also pass an array containing of any of these to easily bind multiple fields to the same suggestions. Second argument is an array of suggestions.
0
8266
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
8199
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8365
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
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
5574
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
4092
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2626
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

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.