简体   繁体   中英

PHP echo variable validation

Trying to do a simple validation. Tutorial shows this in order to do a validation:

<input type="text" name="userName" required tabindex=1><?php if (!is_null($user)) {echo 'value = "'. $user->getUserName() .'"';}?>

However on my file the "value=" displays on my page. So I tried this, putting value inside or outside PHP tags still yields no results.

First name:     
<input type="text" name="firstName" <?php echo 'value = "'. $userData->getFirstName() .'"';?> required tabindex=1>

currently you echo the value outside the close of input, so the browser displays it:

<input type="text" name="userName" required tabindex=1><?php if (!is_null($user)) {echo 'value = "'. $user->getUserName() .'"';}?>

change to

<input type="text" name="userName" required tabindex=1 
<?php if (!is_null($user)) {echo 'value = "'. $user->getUserName() .'"';}?>
 >

demo: http://codepad.viper-7.com/0Zf5EW

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM