我正在创建一个注册页面,当我选择一个特定的部门时,我想自动填充某个输入字段的值。当我选择部门A时。在我注册时,它会自动填写谁是该部门的主管。我会这样做吗?
这是我的html视图代码
<?php if (validation_errors()) { ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-alert" aria-hidden="true"></span><strong> Error!</strong><p><?= validation_errors(); } ?></p></center>
</div>
<?php if (isset($error)){ ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><strong> Error! </strong><?= $error ?> </center>
</div>
<?php } ?>
<div class="container-fluid">
<center> <h2>Register</h2></center>
<hr class="colorgraph">
<form class="form-horizontal" action="<?= base_url().'login/registeruser' ?>" method="post">
<div class="form-group">
<label for="username" class="col-sm-2 control-label "><?php if(form_error('username')){ echo '<p style="color:#a94442"> * Username </p>';} else { echo 'Username'; } ?></label>
<div class="col-sm-6">
<input type="text" class="form-control <?php if (form_error('username')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="username" name="username" placeholder="Username" value="<?php echo set_value('username'); ?>">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label "><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Password </p>';} else { echo 'Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="password" name="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="confpassword" class="col-sm-2 control-label"><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Confirm Password </p>';} else { echo 'Confirm Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="confpassword" name="confpassword" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label "><?php if(form_error('email')){
echo '<p style="color:#a94442"> * Email </p>';} else { echo 'Email'; } ?></label>
<div class="col-sm-6">
<input type="email" class="form-control <?php if (form_error('email')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="email" name="email" placeholder="Email"
value="<?php echo set_value('email'); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label"><?php if(form_error('fname')||form_error('mname')||form_error('lname')){ echo '<p style="color:#a94442"> * Full Name </p>';} else { echo 'Full Name'; } ?></label>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('fname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="fname" name="fname" placeholder="First Name" value="<?php echo set_value('fname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" value ="sa" class="form-control <?php if (form_error('mname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="mname" name="mname" placeholder="Middle Name" value="<?php echo set_value('mname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('lname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="lname" name="lname" placeholder="Last Name" value="<?php echo set_value('lname'); ?>">
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Gender</label>
<label class="radio-inline col-sm-1 control-label">
<input type="radio" name="gender" id="gender" value="M" selected="selected"> Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" id="gender" value="F"> Female
</label>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Department</label>
<select name="Department">
<option value="stem">STEM</option>
<option value="gas">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div>
<div class="form-group">
<div class="col-sm-4 control-label">
<h3><strong>
Captcha
<?=$image; ?></strong></h3>
<input type="text" id="captcha" name="captcha" height="50px" autocomplete="off" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<a href="<?= base_url().'login'; ?>"><button type="button" class="btn btn-default"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> Back</button></a>
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>
</div>
</body>
我想专门使用php代码。我这样做吗?感谢
答案 0 :(得分:0)
您可以使用 jquery ajax 功能。