나는이 작은 문제를 파악하려고 노력해 왔으며 내 머리카락을 꺼낼 준비가되었습니다. 나는 프로그래머보다 디자이너가 더 많지만, 필자는 학교에서 PHP로 제출 양식을 만들었습니다. 여기에 내가 일하고 시험 형태 :PHP 라디오 버튼을 선택한 경우 텍스트 입력란
http://www.inrf.uci.edu/php-form-test/
사람이 외부 사용자를 선택했을 때 내가 뭘하려고 오전, 그들은 그들의 회사 명을 기입해야한다. 누군가 내부 사용자를 선택하면 그룹/PI 이름을 입력해야합니다. 이것은 잘 작동하지 않습니다. 내부를 선택하면 회사 이름이 아닌 그룹/PI 이름 만 필요로합니다. 어떤 도움을 주시면 감사하겠습니다. 고맙습니다! 여기
// internal selected (group pi)
if ($userType == 'internal') {
$internalChecked = ' checked="checked" ';
} else {
if(trim($_POST['grpPI']) === '') {
$grpPIError = '<span class="error">Please enter your group or PI name.</span>';
$hasError = true;
} else {
$grpPI = trim($_POST['grpPI']);
}
}
}
// external selected (company name)
if ($userType == 'external') {
$externalChecked = ' checked="checked" ';
} else {
if(trim($_POST['companyName']) === '') {
$companyNameError = '<span class="error">Please enter your company name.</span>';
$hasError = true;
} else {
$companyName = trim($_POST['companyName']);
}
}
및 HTML :
<table class="usertype" id="usertype">
<tr>
<td colspan="2">
<input type="radio" name="userType" value="external" <?php echo $externalChecked; ?>>External
<select name="externalSelect" size="1">
<option selected="selected">Select</option>
<option>Academic</option>
<option>Non-Profit</option>
<option>Commercial</option>
</select><?php if($externalError != '') { ?><span class="error"><?=$externalError;?></span><?php } ?></td>
</tr>
<tr>
<td colspan="2"><label for="companyName">Company Name:</label>
<input type="text" size="40" name="companyName" id="companyName" value="<?php if(isset($_POST['companyName'])) echo $_POST['companyName'];?>" />
<?php if($companyNameError != '') { ?>
<span class="error"><?=$companyNameError;?></span><?php } ?></td>
</tr>
<tr>
<td colspan="3"><input type="radio" name="userType" value="internal" <?php echo $internalChecked; ?>>Internal <input title="Enter Account String. Required for Internal Users." type="text" size="30" name="ucfund" value="<?php if(isset($_POST['ucfund'])) echo $_POST['ucfund'];?>" placeholder="KFS or Account (eg. xxxxxxx)" /><?php if($ucfundError != '') { ?><span class="error"><?=$ucfundError;?></span><?php } ?> - <input title="Enter Fund String. Required for Internal Users." type="text" size="25" name="ucfund2" value="<?php if(isset($_POST['ucfund2'])) echo $_POST['ucfund2'];?>" placeholder="Fund (eg. xxxxx)" /><?php if($ucfund2Error != '') { ?><span class="error"><?=$ucfund2Error;?></span><?php } ?><br /><span class="small">(Please enter KFS number or Accound Fund)</span>
</td>
</tr>
<tr>
<td colspan="3">Optional <input type="text" size="30" name="sub" value="<?php if(isset($_POST['sub'])) echo $_POST['sub'];?>" placeholder="Sub" /><?php if($subError != '') { ?><span class="error"><?=$subError;?></span><?php } ?> - <input type="text" size="25" name="proj" value="<?php if(isset($_POST['proj'])) echo $_POST['proj'];?>" placeholder="Project" /><?php if($projError != '') { ?><span class="error"><?=$projError;?></span><?php } ?>
</td>
</tr>
<tr>
<td colspan="3"><label for="grpPI">Group/PI:</label>
<input type="text" size="40" name="grpPI" id="grpPI" value="<?php if(isset($_POST['grpPI'])) echo $_POST['grpPI'];?>" />
<?php if($grpPIError != '') { ?>
<span class="error"><?=$grpPIError;?></span><?php } ?></td>
</tr>
</table>
어디'$ userType'가 결정됩니다 두 개의 코드 경로 중 하나만 실행되도록
당신은 함께 두if()
문을 묶어하는else
절을해야합니까? 코드가 예상 한 것과 다르게 동작하기 시작한 곳을 확인하기 위해 디버깅을 했습니까? –'($ userType == 'internal') ELSE IF ($ userType == 'external') ... ' –
'var_dump ($ userType);'사용자 유형이 서버에 분명히 존재하지 않게하십시오. 그것을 보내고'$ _POST'를 사용하여 가져와야합니다. – Abel