Jump to content

Displaying error messages in form when php is separate file


robmo

Recommended Posts

Hi,

 

I have a separate form created using Dreamweaver that calls a separate php script when the Submit button is clicked. Currently I am able display form validation messages in a new html page. If the user leaves fields blank, I would like the messages to appear on the form itself instead of in a new page.

 

How do you make the messages from the php form validation code display into the calling html form? I know I could just do this with Dreamweaver but I would like to learn to do this using php.

 

It might be easier to embed the code within the html page but I was thinking that using the separate script would be more secure.

 

My form can be found here. Validation is working but opens a new page:

http://www.tallfirshoa.com/adform.htm

 

Thanks!

Rob

 

Link to comment
Share on other sites

Javascript would be your friend in this case, if the form validation doesn't require checking against a database.  If it does, look into using AJAX to execute your PHP script that checks for errors so the user doesn't actually leave the form page.

 

Theo

Link to comment
Share on other sites

I don't need a database in this example. The script only needs to check for blank fields and let the user know that they need to be filled out. If everything is filled out, then php should email the results of the form to me and one other person. I want to include captcha to so it helps to prevent spam.

 

Maybe my php script doesn't need to do as much as I am thinking.

Link to comment
Share on other sites

Use Javascript then.  Use an onSubmit() event handler in your form tag to run an error checking function in Javascript that checks to make sure the form doesn't contain any blank fields.  If it does, throw up an alert() or something similar to notify the user to correct their mistakes.  If not, proceed to submit the form.  Since this is a matter of not moving to another page, you will need to use client-side scripting to accomplish this, not server-side.  If you are gung-ho about using PHP to error check, you will need to use AJAX.

Link to comment
Share on other sites

Mainly I just want to follow best practice out in the industry. It sounds like javascript is how it would be done. I do know that if I just use Dreamweaver to set the conditions, it will write the javascript for me. This sounds like the easiest way to go.

 

I'm not necessarily looking for easy, just the best and most popular solution. I don't really want to create a big mess that is hard to understand and maintain.

 

Thanks a lot for your help! I think I know what I need to do now...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.