I have a php script that sends the contents of a form via email.

I have some error checking in the script to make sure that the required fields are filled out. Right now, if there's an error, it just displays an error, with what's missing on a simple html page.

I want to be able to have this error appear within a page that looks like the rest of my website.

My question is, how can I pass the error message so that it is displayed on a pre-constructed html page? I don't want to have to create a new page for each error.

Does that make sense?

Thanks.

There are a couple ways to do it.

1. AJAX

2. Self-validating page/form

AJAX is a procedure (not a language) that uses JavaScript, XML, and PHP to dynamically change the contents of a web page without completely reloading it. You would use JavaScript to get information from your form and send it, via XML, to your PHP script. The script would then send information back to the JavaScript on how to update the page. Find more info and a tutorial here.

Another option is a self-validating form. A self-validating form has areas hidden within it for error reporting and sends its data to itself when submitted. Script that executes before the form displays does all the validation and performs the necessary actions if the submission is valid.

Hope that helps.

you have to study error handling.... you have to work on try catch

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.