douyan1927 2018-06-04 12:40 采纳率: 0%
浏览 44
已采纳

PHP总是从HTML表单中获取特定值

I have a HTML form in a wordpress site that sends data to a database. One of the fields asks if a person is male or female using a radio button. How ever even if the persons presses the "Female" radio button they get set to male (Status M)

I've attached my code, the <?php if( get_theme_mod( 'petition_zip' ) === true ) : ?> is only a check in my wordpress theme to see if the field should be there. I first tried using only HTML but added some PHP later to try and remidy the problem, it did not so as far as I can tell the PHP attached is close to useless

<?php
    $male_status = 'unchecked'; 
    $female_status = 'unchecked'; 
    if (isset($_POST['submit'])) {
        $selected_radio = $_POST['zip'];
        if ($selected_radio == 'M') {

            $male_status = 'checked';

            }
            else if ($selected_radio == 'F') {

            $female_status = 'checked';

            }

    }
?>
            <?php if( get_theme_mod( 'petition_zip' ) === true ) : ?>
            <div class="form-group">

                <input type="radio" id="zip" name="zip" value="M" <?PHP print $male_status; ?>>
                <label for="M">Male</label>

                <input type="radio" id="zip" name="zip" value="F" <?PHP print $female_status; ?>>
                <label for="F">Female</label>   
                </div>

            <?php endif; ?>

I'm running queries on the database to confirm the status, everyone that signs up is put to status "M" (Male)

  • 写回答

2条回答 默认 最新

  • dragon7088 2018-06-05 08:22
    关注

    The error is possibly in your petition.sign.js file.

    I would try to replace this line:

    $zip = $( 'input[name="zip"]', this ).val();
    

    with this

    $zip = $('input[name=zip]:checked').val();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀