Want to Make Webpage Display Error if Checkbox Not Checked


Recommended Posts

I have a simple contact form I'm using for potential clients to send me their information. I'm using a simple PHP script to email the form contents, which works fine. However, what I want to do is make it so that if a disclaimer checkbox is not checked, then the email will not send, and the user will see an error message.

I don't want a dialog box or anything. What I have right now is red text that describes the error, but its default display style is set to hidden in my CSS sheet. What I'd like is for it to become visible if the checkbox is not checked, so that the user knows why the contact failed.

Additionally, I have 3 areas of the form that are marked "required." I'd also like something similar to happen if any one of them is not filled in. Like if the "Name" box has not been edited, then red text appears that says something like, "You must enter your name." or something. Obviously I'm an extreme novice, so any help is much appreciated. Thanks.

Link to comment
Share on other sites

Basically what you want is a page that goes something like this:

// set form default $values

if( !emtpy($_POST) ) {

// update the forms $values with posted values

// validate the $values and collect any error messages


// show page header

if( !empty($validation_messages) ) {

// show the validation messages


// show the form using the $values

// show page footer


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.