Jump to content

Recommended Posts

Hi, I've just started learning PHP, and I'm trying to finish a contact form I've made.

I have [i]contact.htm [/i] which goes to [i]mailer.php[/i]. I have written some JavaScript validation of the form, and I am going to use server-side validation too. Problem is, (let's say JS is turned off) I have no idea how to go back to the contact form if the input is incorrect, with the values still in the fields, then display the relevant error message.

I was thinking I could have some error messages with [b]display:none[/b], which I then switch to [b]display:inline[/b] but I really have no idea how to do that with PHP (if you can at all).

Ok, basically, how do I send the user back to contact.htm after PHP validation fails, with the form remaining as it was, and alert them to the errors?

Thanks.

[b]Edit:[/b] I understand how to do it if I just use one php page. Is this advisable?
Link to comment
https://forums.phpfreaks.com/topic/20633-help-a-php-noob-please/
Share on other sites

You can do it all in one page... there's no reason against doing this.

BUT, if you wanted to use 2, you could easily do your validiation on mailer.php and if the validation failes, simply use the header() function to redirect them.  You still have to change the form page to a php page and include the error messages in case you have to go back and so on and so on. 

Long story short, it's easier to do it all within the same page and leave the validation to PHP.
Link to comment
https://forums.phpfreaks.com/topic/20633-help-a-php-noob-please/#findComment-91165
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.