开发者

Inline php with forms

<?php
echo '<f开发者_如何学JAVAorm action="';
echo $_SERVER['PHP_SELF']; 
echo '" method="post"><input class="loginDropdownInput" type="text" name="user" value=';
if(isset($_COOKIE['rememeredusername'])=='true'){
  echo $_COOKIE['rememeredusername'];
} else {
  echo 'Username';
}
echo 'onclick="if(this.value == "Username") this.value="";" onblur="if(this.value.length == 0) this.value="" Username""; /></br></br><input class="loginDropdownInput" type="password" name="pass" value="Password" onclick="if(this.value == "Password"") this.value="";"  onblur="if(this.value.length == 0) this.value="Password";"/>
?>

<span>
  </br>
  </br>
  <span class="rememberMe">Remember me</span>
  <input class="rememberMeBox" value="rememberme" name="rememberme" type="checkbox"/>
</span>

<a class="forgotPassword" href="../Accounts/forgot.php">Forgot your password?</a>

<?php
echo '<p class="loginErrorMessage">';
if ($userexists=='false'){
  echo "Uh oh, try again...";
}  
echo'</p><input class="submitDropdownInput" type="image" src="../Images/submitDropdownInput.png" alt="Login"/></form>';
?>

This is my code for a login portion of my site. However, input.loginDropdownInput keeps coming out with a value of "Usernameonclick="if(this.value" instead of "Username". Where is my syntax error?


I don't know what exactly are your needs, but I would seriously recommend you to stop mixing so much PHP and markup like you're doing right now, it's horrible to read and almost impossible to maintain.

Try doing something like:

PHP part:

if (isset($_COOKIE['rememeredusername'])){ 
  $form['username'] = $_COOKIE['rememeredusername'];
} else {
  $form['username'] = "Username";
}
$form['username'] = htmlspecialchars($form['username']);

HTML part:

<form action="" method="post">
<input class="loginDropdownInput" type="text" name="user" value="<?=$form['username']?>"
  onfocus="if(this.value == 'Username') this.value='';"  
  onblur="if(this.value.length == 0) this.value='Username';" />

Also you were using the onclick event, when you actually want it to be onfocus.

That's what I could understand from your code, try to make your php reproduce something like this if this is what you need.

-- Fixed some code errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜