I need a PHP code so if someone typed in nothing in a field, it makes a JavaScript popup saying 'Please enter a message' or something.
Correctable (Forum Moderator) - Thread moved to Coding. Please post in the correct sections.

I need a PHP code so if someone typed in nothing in a field, it makes a JavaScript popup saying 'Please enter a message' or something.
Correctable (Forum Moderator) - Thread moved to Coding. Please post in the correct sections.
Last edited by lMattz; 09-08-2006 at 08:12 AM.
Try something like
PHP Code:if($message == "") { echo "You haven't entered a message"
PHP Code:[LEFT]<?[/LEFT]
[LEFT]$name = $_GET['name'];[/LEFT]
[LEFT]echo "Hi, your name is $name";[/LEFT]
[LEFT]?>[/LEFT]
[LEFT][/LEFT]
Thanks will try.
Edit: Thats not a complete code, the echo tag looks uncompleted.
Last edited by Drugs; 08-08-2006 at 08:49 PM.
You could try a javascript. In your form code put
then in the HEAD tag of your page putCode:<form name="shoutbox" onsubmit="return validate()">
Code:<SCRIPT>function validate() { with (document.form1) { var alertMessage = "The following field is empty:\n"; if (name.value == "") { alertMessage += "\name" } if (message.value == "") { alertMessage += "\message" } if (alertMessage != "The following field is empty:\n") { alert(alertMessage); return (false); } return (true) } }</SCRIPT>
Last edited by Fujitsu; 08-08-2006 at 08:54 PM.
PHP Code:[LEFT]<?[/LEFT]
[LEFT]$name = $_GET['name'];[/LEFT]
[LEFT]echo "Hi, your name is $name";[/LEFT]
[LEFT]?>[/LEFT]
[LEFT][/LEFT]
Sorry for double post ;P
I used the following code;
if ($name == "") {
echo "Please enter a Name";
}
But when it comes up with "Please enter a name" it just redirects to the shoutbox and still submits the message.
Just do:
PHP Code:
if(!$name) {
echo "
<script language='javascript'>
alert('Fill in your name');
</script>
";
}
Try
But looking at Sygon's code, that should work.PHP Code:<?php echo("Wouldn't Work, Code Removed"); ?>
Last edited by Fujitsu; 08-08-2006 at 09:01 PM.
PHP Code:[LEFT]<?[/LEFT]
[LEFT]$name = $_GET['name'];[/LEFT]
[LEFT]echo "Hi, your name is $name";[/LEFT]
[LEFT]?>[/LEFT]
[LEFT][/LEFT]
Sygon i used that but go to the site and type something in with no name..
When you press ok on the alert, it just goes back to the shoutbox and types it in anyway.
Fujitsu still typed it in anyway
Last edited by Drugs; 08-08-2006 at 09:00 PM.
Wrong section
Correctable (Forum Moderator) - Please do not post pointlessly acting like a moderator.
Last edited by lMattz; 09-08-2006 at 08:14 AM.
@ Chris
So, does it really matter?
Correctable (Forum Moderator) - Please stay on topic
Last edited by lMattz; 09-08-2006 at 08:14 AM.
PHP Code:[LEFT]<?[/LEFT]
[LEFT]$name = $_GET['name'];[/LEFT]
[LEFT]echo "Hi, your name is $name";[/LEFT]
[LEFT]?>[/LEFT]
[LEFT][/LEFT]
Want to hide these adverts? Register an account for free!