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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序