PHP forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tiresome
Forum Newbie
Posts: 16
Joined: Sun Apr 18, 2004 9:45 am

PHP forms

Post by tiresome »

I am using an HTML form to request data from the user and submitting it to a PHP file to process the data and display the results. Is it possible to do this just using one PHP file instead of having to write a separate HTML file?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

just use one php file (index.php)
and set the form action to $PHP_SELF

and make use of the isset() function

and also - this board is for code snipplets, not questions(least not related to the topic).

:o
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Yes but it's better to keep the presentation in a separate layer.

I'd suggest:

- a php script to handle form display (set any vars required for the form)
- a html file with the form (echo out any php vars here)
- a form submission handler which validates user input, and decides whether to redisplay the form (with error messages & valid, redisplayed user input) or process the submission
- a form submission processor which processes the form

The handler should receive a message from the processor with information about the success or otherwise of the processing. The handler can then show a page with this messgae.
Post Reply