How do I write...PHP Code:<?
function emptyform(){
if($username=="" || $password==""){
print "You Have To Write Both Of Your Username And Password!<br><br>";}
}
?>
<input type="submit" value="Login" onClick="emptyform()"> Or how ??
| SitePoint Sponsor |


How do I write...PHP Code:<?
function emptyform(){
if($username=="" || $password==""){
print "You Have To Write Both Of Your Username And Password!<br><br>";}
}
?>
<input type="submit" value="Login" onClick="emptyform()"> Or how ??


Are you trying to call the function emptyForm() when a user clicks the submit button? If so you'll need to write the function in Javascript.
-Bryan





Ok the HTML should be something like:
<input type="text" name="username">
<input type="submit" name="submit">
Then the php:
PHP Code:<?
if (isset($_POST['submit'])){
emptyform();
}
else{
}
function emptyform(){
if($_POST['username']=="" || $_POST['password']==""){
print "You Have To Write Both Of Your Username And Password!<br><br>";}
}
?>
"A nerd who gets contacts
and a trendy hair cut is still a nerd"
- Stephen Colbert on Apple Users


Thanks, I'll try it![]()
By the way, yes I wont it to be called when the user clicks on the sumbit... bcp_2005
Originally posted by sleepingdanny
Thanks, I'll try it![]()
By the way, yes I wont it to be called when the user clicks on the sumbit... bcp_2005
You cant do it that way with PHP, you have to either use Javascript or check the inputted values on another page.
THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
OVER YOUR DOG. <-- MediaWiki installation guide


Yes, the only way to do that would be to write the function in Javascript. There's probably a post on the Javascript forum that'll tell you how do do it. If not try searching for it.
-Bryan
Bookmarks