Jump to content

Recommended Posts

Hi folks, I have this site and idea

 

http://www.helraizer.co.uk/mychatbox/

 

at the moment I'm using javascript to alert the user if they haven't entered a username or message but all this does is popup an alert message and return false. However, if their browser does not support javascript (javascript is turned off) then it just won't send and will give them no reason why.

 

How would I get it so that, using php, if the submit button is pressed and either the username is less than 3 characters and/or the comment field is less than 5 characters then above the image (on the site page) a list of errors would appear.

 

So if nothing was wrong it shows no errors but if the user name was less than 3 characters and comment <5 it'd appear

"Error!

-Your username is too short, please enter a user name between 3 and 10 characters.

-Your comment is too short, please enter a comment between 5 and 75 characters." (or similar)

 

How would I do this?

 

I know this is a "help" forum not a "do it for me forum" but if you guys can give me a baseline for this problem, to work with from there I can probably get it from there. :)

 

Thanks,

Sam

Link to comment
https://forums.phpfreaks.com/topic/89283-alert-user-of-errormissing-data-in-form/
Share on other sites

you could add a check like this in your php code to check for emtpy fields

 

<?php
if($_GET['username']!='' && strlen($_GET['username'])>3 && $_GET['input'] && strlen($_GET['input'])>5){
    //update message board
}else{
    //put a message out saying form filled incorect
}
?>

 

Scott.

Sorry, but you would be best off ignoring the previous poster for the reasons you stated in your first post - if the user has javascript turned off this will not work. Your best bet is to do what you are thinking of, and create a php solution, then overlay a javascript solution as a supplement to the php.

 

I basically do what ratcateme does. I check for the different requirements of the field, and if they aren't met, I store an error message into an array I call $errors. After checking for all the fields, I check to see if $errors[0] is null (i.e. no errors in the form). If its null, then I proceed with processing the error. If its not null (i.e. errors were found in the form input),  then I use a loop to output each of the errors stored in $errors, followed by the form itself so they can re-submit the information.

 

Good luck! Try some script out and post it here if you are having some troubles.

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.