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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据