mehdi mehdi - 1 year ago 66
Ajax Question

Empty form with for statement

I have a

statement to create 20 number of forms, but after creating elements my forms look like empty(but I have input elements on it) and that is why I cannot send objects with POST.

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

this is my code :

for($i= 1 ; $i<=$numtest ; $i++){
$mdata = $numtoword->ToWordFa($i);
echo '
<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>
<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/>

Ajax will put input elements in this div of above code :

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

how can moderate that?

thanks in advance

Answer Source

When you use :: you are trying to access a method statically so your function signature should be declared as: public static function toWord2().

I think you defined your method toWord2 as non-static and you are trying to invoke it as static. That said.

1) If you want to invoke a static method, you should use the :: and define your method as static.

// Defining a static method in a Foo class.
public static function toWord2() { /* code */ }

// Invoking that static method

2) otherwise, if you want to invoke an instance method you should instance your class, use ->.

// Defining a non-static method in a Foo class.

    public function toWord2() { /* code */ }

    // Invoking that non-static method.
    $objNumericHelper = new NumericHelper();

You can ride same thing about OOP & static methods in PHP