gpt4 book ai didi

php - 如何最好地使用 php 预填充单选按钮选择?

转载 作者:搜寻专家 更新时间:2023-10-31 20:45:59 24 4
gpt4 key购买 nike

我正在处理申请表。

它会预先填充一个人的详细信息,我们已经有了他们的详细信息。基本上我们会向他们发送一个链接到他们的表格,其中已经填充了他们的详细信息,然后我们只是要求他们检查表格并在所有信息正确时点击提交。

我有以下内容来预填充简单的文本框:

<input type="text" name="forename" id="input-forename" value="<?php echo htmlspecialchars(@$_REQUEST['forename']);?>"/>    

<input type="text" name="birthdate" id="input-birthdate" value="<?php echo htmlspecialchars(@$_REQUEST['date_of_birth']);?>" />

等等

一切都很好。

不过我在使用单选按钮时遇到了困难。

这个选择例如:

<label for="input-title-mr">Mr: <input type="radio" name="title" id="input-title-mr" value="Mr" /></label>
<label for="input-title-mrs">Mrs: <input type="radio" name="title" id="input-title-mrs" value="Mrs" /></label>
<label for="input-title-miss">Miss: <input type="radio" name="title" id="input-title-miss" value="Miss" /></label>
<label for="input-title-ms">Ms: <input type="radio" name="title" id="input-title-ms" value="Ms" /></label>

是否有可能使用 checked=""属性和 php if 语句来预先检查正确的单选按钮的好方法?

也许是这样的:

<label for="input-title-mr">Mr: <input type="radio" name="title" id="input-title-mr" value="Mr" checked="<?php if ( @$_REQUEST['forename'] == 'Mr' ) { echo 'checked'; }?>" /></label>

我希望这是有道理的,任何帮助或建议将不胜感激:)

最佳答案

<input type="radio" name="title" id="input-title-mr" value="Mr" <?php echo ($_REQUEST['title'] == 'Mr') ? 'checked="checked"' : ''; ?>  />

关于php - 如何最好地使用 php 预填充单选按钮选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13306218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com