停止我的循环以注册数据两次

时间:2015-04-20 作者:Dougless

我在这里面临一个问题。

下面的代码正在我的网站上运行,当我填写表单并检查数据库时,数据已经注册了两次。

请从我的函数中输入以下php代码。php文件。

function map_location_report_form()
    {

        global $wpdb;

        $this_page  =   $_SERVER[\'REQUEST_URI\'];
        $page       =   $_POST[\'page\'];

        if ( $page == NULL )
        {
            echo \'<form method="post" action="\' . $this_page .\'">

                    <div class="formfield-report" id="formfield-report-firstname">
                        <label for="first_name" id="first_name">Navn: </label>
                        <input type="text" name="first_name" id="first_name" />
                    </div>

                    <div class="formfield-report" id="formfield-report-lastname">
                        <label for="last_name" id="last_name">Efternavn: </label>
                        <input type="text" name="last_name" id="last_name" />
                    </div>

                    <div class="formfield-report" id="formfield-report-locationtype">
                        <label for="location_type" id="location_type">Rapport type: </label>
                        <select name="location_type" />
                            <option value="sigtmelding" selected>Sigtmelding</option>
                            <option value="fangstrapport">Fangstrapport</option>
                            <option value="jagtomraade">Jagtområde</option>
                        </select>
                    </div>

                    <div class="formfield-report" id="formfield-report-latitude">
                        <label for="location_latitude" id="location_latitude">Breddegrad: </label>
                        <input type="text" name="location_latitude" id="location_latitude" />
                    </div>

                    <div class="formfield-report" id="formfield-report-longitude">
                        <label for="location_longitude" id="location_longitude">Længdegrad: </label>
                        <input type="text" name="location_longitude" id="location_longitude" />
                    </div>

                    <input type="hidden" value="0" name="page" />

                    <div id="formfield-report-button">
                        <input class="btn btn-default submit-form-button" type="Submit" />
                    </div>

            </form>\';
        } //End Page 1 of Form
        // Start Page 2 of Form
        elseif ( $page == 0 )
        {
            $first_name             =   $_POST[\'first_name\'];
            $last_name              =   $_POST[\'last_name\'];
            $location_type          =   $_POST[\'location_type\'];
            $location_latitude      =   $_POST[\'location_latitude\'];
            $location_longitude     =   $_POST[\'location_longitude\'];
            $page                   =   $_POST[\'page\'];

            $page_one_table = \'maplocationreports\';

            $page_one_inputs =  array
            (
                \'first_name\'            => $first_name,
                \'last_name\'             => $last_name,
                \'location_type\'         => $location_type,
                \'location_latitude\'     => $location_latitude,
                \'location_longitude\'    => $location_longitude,
                \'page\'                  => $page
            );

            $insert_page_one = $wpdb->insert($page_one_table, $page_one_inputs);

            echo \'<h3>Mange tak for dit bidrag!</h3>\';
            echo \'<p>Der er sat stor pris på at du har taget dig tid til at registrere et punkt på kortet!</p>\';
        } // End Page 2 of Form
    };

    add_shortcode(\'map_location_report\',\'map_location_report_form\');
如何阻止此代码两次注册数据?

1 个回复
SO网友:Trang

尝试将此代码添加到站点的js

$(\'form\').unbind(\'submit\').submit();
按演示用户:https://stackoverflow.com/questions/9767871/jquery-submitting-a-form-twice

结束

相关推荐

为什么自定义MySQL查询不返回结果?语法正确吗?

第一次进行自定义查询。我在寻找一种方法来获取某个分类法的类别列表,以便可以为自动完成函数运行类似的查询。为了得到一些结果,我提出了mysql查询,它在phpMyAdmin中给出了结果SELECT * FROM wp_terms INNER JOIN wp_term_taxonomy ON ( wp_terms.term_id = wp_term_taxonomy.term_id ) WHERE wp_terms.name LIKE \'ca%\' AND count