PHP forms
Moderator: General Moderators
PHP forms
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?
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.
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.