【问题标题】:Empty form with for statement带有 for 语句的空表单
【发布时间】:2015-10-06 18:37:40
【问题描述】:

我有一个 for 语句来创建 20 个表单,但是在创建元素之后,我的表单看起来像空的(但我上面有输入元素),这就是为什么我不能使用 POST 发送对象。

<form method="post" ></form>

这是我的代码:

for($i= 1 ; $i<=$numtest ; $i++){
        $mdata = $numtoword->ToWordFa($i);
        echo '
            <li>
                <div class="questitle2 noselect"><a href="#">عنوان سوال '.$mdata.'</a></div>
                <div class="quescontent">
                    <input type="text" class="questitle byekan" name="tt'.$i.'" id ="tt'.$i.'" placeholder="عنوان سوال '.$i.'" onclick="select()" /><br/>
                    <div style="text-align:right;margin-top:10px;" class="qkind">نوع سوال :
                                <input type="radio" name="istest'.$i.'" id="is2test'.$i.'" value="yt2" onclick="add_choice(\'c'.$i.'\' , \'yt2\');" /><label for="is2test'.$i.'"><span class="noselect fade"> 2 گزینه ای</span></label>
                                <input type="radio" name="istest'.$i.'" id="is4test'.$i.'" value="yt4" onclick="add_choice(\'c'.$i.'\' , \'yt4\');" /><label for="is4test'.$i.'"><span class="noselect fade"> 4 گزینه ای</span></label>
                                <input type="radio" name="istest'.$i.'" id="nottest'.$i.'" value="nt2" onclick="add_choice(\'c'.$i.'\' , \'nt2\');"/><label for="nottest'.$i.'"><span class="noselect fade"> تـشریحی</span></label>
                    </div> 
                    <form method="post" >
                        <input type="hidden" name="tid1" value="'.$tkey.'"/>
                        <input type="hidden" name="thisquestion1" value="'.$i.'"/>
                        <div class="choosepart" id="c'.$i.'"></div>
                        <div id="res"> </div>
                        <input class="fade" id="sc'.$i.'" style="margin-top:5px;" type="button" name="Send" onclick="formget( this.form  , \'tests.php\' , \'res\' , \'dd\' ,\''.$i.'\');" value="ثبت این سوال" disabled/>
                    </form>
                </div>
            </li>
        ';
    }

Ajax 会将输入元素放在上述代码的这个 div 中:

<div class="choosepart" id="c'.$i.'"></div>

如何调节它?

提前致谢

【问题讨论】:

    标签: javascript php ajax forms for-loop


    【解决方案1】:

    当您使用:: 时,您正在尝试静态访问方法,因此您的函数签名应声明为:public static function toWord2()

    我认为您将方法 toWord2 定义为非静态的,并且您试图将其调用为静态的。就是这么说的。

    1)如果你想调用一个静态方法,你应该使用::并将你的方法定义为静态的。

    // Defining a static method in a Foo class.
    public static function toWord2() { /* code */ }
    
    // Invoking that static method
    NumericHelper::toWord2();
    

    2)否则,如果你想调用一个实例方法,你应该实例化你的类,使用-&gt;

    // Defining a non-static method in a Foo class.
    
        public function toWord2() { /* code */ }
    
        // Invoking that non-static method.
        $objNumericHelper = new NumericHelper();
        $objNumericHelper->toWord2();
    

    你可以骑同样的东西about OOP & static methods in PHP

    【讨论】:

    • 谢谢,我更正了,现在没有错误了,我的表格还是空的!!
    • 我的荣幸!如有任何相关疑问/疑虑,请随时联系。
    【解决方案2】:

    请在for 语句之后放置以下代码,此代码将告诉您问题/错误是什么/在哪里。如果需要我们的更多帮助,请告诉我。

    //This code will suggest what/where is the error
    
    print("<pre>");
    print_r(error_get_last());
    print("</pre>");
    

    希望对你有所帮助。

    谢谢!

    【讨论】:

    • 谢谢你,我添加代码并输出: Array ( [type] => 2048 [message] => 非静态方法 NumericHelper::toWord2() 不应被静态调用 [file ] => /home/cp18276/public_html/miniworks/2/include/classes.php [行] => 130)
    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    • 2014-08-30
    相关资源
    最近更新 更多