如何制作一个单选按钮来控制所有这些?

时间:2022-10-31 15:51:47

When visitors register on my site, they will do so as the founding member of a group or as a person joining an existing group. Nobody is "group-less." I have a single registration page with the following fields: first name, last name, (radio buttons to choose group type: New or Existing), group name, group password, email, pass, confirm pass. I'm concerned specifically with the radio buttons, group name, and group password.
The specific function I'm looking for is this: If "New" is selected, AJAX checks if group name exists in database, displays either "Good" or "Already taken." ALSO: when form is submitted, password saved to database.
If "Existing" is selected, AJAX checks if group name exists in db, displays either "Matched" or "Non-existent." ALSO: when form is submitted, password checked against database.

当访问者在我的网站上注册时,他们将作为一个组的创始成员或加入现有组的人员进行注册。没有人是“无团体”。我有一个注册页面,其中包含以下字段:名字,姓氏,(用于选择组类型的单选按钮:新建或现有),组名称,组密码,电子邮件,通过,确认通过。我特别关注单选按钮,组名和组密码。我正在寻找的具体功能是:如果选择“新建”,AJAX会检查数据库中是否存在组名,显示“正常”或“已经采取”。另外:提交表单时,密码保存到数据库。如果选择“现有”,AJAX将检查db中是否存在组名,显示“已匹配”或“不存在”。另外:提交表单时,会根据数据库检查密码。

The basics of this I think I have a handle on, but how to get the radio button to dictate so much is beyond me. Any help would be appreciated.

这个基础知识我认为我有一个处理,但如何让单选按钮指示这么多是超出我的。任何帮助,将不胜感激。

Below is the form part of my php file. (By the way, I've been writing mysqli for this project.)

下面是我的php文件的表单部分。 (顺便说一句,我一直在为这个项目写mysqli。)

<h1>Register</h1>
<form action="register.php" method="post">
    <fieldset>

    <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></p>

    <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></p>

  <p><b>Are you registering a new group or joining an existing group?</b> <br />
  New:<input type="radio" value="new" name="gtype">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  
  Existing:<input type="radio" value="existing" name="gtype">  </p>

    <p><b>Group ID:</b> <input type="text" name="group_id" size="20" maxlength="40" value="<?php if (isset($trimmed['group_id'])) echo $trimmed['group_id']; ?>" /></p>

    <p><b>Group Password:</b> <input type="password" name="gpass" size="8" maxlength="5" /> 
      <small>Use only numbers. Must be 5 digits long.</small></p>

    <p><b>Email Address:</b> 
    <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" onBlur='checkEmail(this)'/><span id='info'></span></p>

    <p><b>User Password:</b> 
      <input type="password" name="password1" size="8" maxlength="4" /> 
      <small>Use only numbers. Must be 4 digits long.</small></p>
    <p><b>Confirm Password:</b> <input type="password" name="password2" size="4" maxlength="4" /></p>
    </fieldset>

    <div align="center"><input type="submit" name="submit" value="Register" /></div>
    <input type="hidden" name="submitted" value="TRUE" />

</form>

1 个解决方案

#1


0  

I suggest using jquery:

我建议使用jquery:

Detect the change of the radio button, like this:

检测单选按钮的更改,如下所示:

$("input[@name='gtype']").change(

Grab the content of the text input containing the group name, and send it to a PHP script.

获取包含组名的文本输入的内容,并将其发送到PHP脚本。

$.ajax
        ({
            url: 'Apps/CheckGroupName.php',
            type: 'POST',
            data: 'groupName=' + groupName,

            success: function(result)
            {
                // Do whatever you need to do based on the result
            }
        });

In the PHP script, check the group name in the database, and echo the result. In JQuery, that result will end up in success: function (result), where you can do whatever you need to do (like warn the user, or confirm that the group doesn't exist.

在PHP脚本中,检查数据库中的组名称,并回显结果。在JQuery中,结果将最终成功:函数(结果),您可以在其中执行任何操作(例如警告用户,或确认该组不存在)。

#1


0  

I suggest using jquery:

我建议使用jquery:

Detect the change of the radio button, like this:

检测单选按钮的更改,如下所示:

$("input[@name='gtype']").change(

Grab the content of the text input containing the group name, and send it to a PHP script.

获取包含组名的文本输入的内容,并将其发送到PHP脚本。

$.ajax
        ({
            url: 'Apps/CheckGroupName.php',
            type: 'POST',
            data: 'groupName=' + groupName,

            success: function(result)
            {
                // Do whatever you need to do based on the result
            }
        });

In the PHP script, check the group name in the database, and echo the result. In JQuery, that result will end up in success: function (result), where you can do whatever you need to do (like warn the user, or confirm that the group doesn't exist.

在PHP脚本中,检查数据库中的组名称,并回显结果。在JQuery中,结果将最终成功:函数(结果),您可以在其中执行任何操作(例如警告用户,或确认该组不存在)。