We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21702
    • 10 Posts
    Hello,

    Ok, i try in english smiley
    I’m new to modx and i ’ve a strange problem with an edit(update in database) eform :

    I need to show/edit a form before valid and update to DB.

    I get all input value but one textarea and one radioBtn can’t showing values...

    here the code of my call chunk :


    <h3 style="margin-left:50px;">Edition du projet</h3>
                     <div id="mainEdit"><br/> 
    
                     [[getCase]]
                     [[updateCase2db]]
                     [!eForm? &noemail=`true` &formid=`updateCaseForm`  &eFormOnBeforeMailSent=`updateCase2db` &tpl=`form_edition` &thankyou=`updateFormResult` &pos=`[+positioncase+]` &clientname=`[+clientname+]` &title =`[+titlecase+]` &text=`[+textcase+]` &type=`[+typecase+]` &link=`[+linkcase+]` &typeTitle=`[+typetitlecase+]` &print=`[+tagprint+]` &web=`[+tagweb+]` !]


    In this chunk, i get all informations in BD (SELECT) with the snippet [[getCase]] and set all my placeholders ...

    snippet getCase :
    ...
    $modx->setPlaceholder('positioncase', mysql_escape_string($irow['position']));
    $modx->setPlaceholder('clientname', mysql_escape_string($irow['clientname']));
    $modx->setPlaceholder('titlecase', mysql_escape_string($irow['title']));
    $modx->setPlaceholder('textcase', mysql_escape_string($irow['text']));
    $modx->setPlaceholder('typecase', mysql_escape_string($irow['projectType']));
    $modx->setPlaceholder('linkcase', mysql_escape_string($irow['projectLink']));
    $modx->setPlaceholder('typetitlecase', mysql_escape_string($irow['projectTypeTitle']));
    $modx->setPlaceholder('tagprint', $print);
    $modx->setPlaceholder('tagweb', $web);
    
    return;
    ?>


    I can’t get the value of [+textcase+] and [+tagPrint+] / [+tagWeb+], even if i put a
    "return getChunk(’form_edition’);" instead of "return;"
    But this is not what i want because with the &tpl param (&tpl=`form_edition`), that showing 2 times my form.
    here is the form ( form_edition )

    [+validationmessage+]
    <form method="post" class="jNice" name="updateCaseForm" enctype="multipart/form-data" action="[~[*id*]~]]"> 
    
    <table id="editCaseForm" >
            <tr>
                <td> 
                <label for="posPrj">Position du projet : </label><br/>
                <input type="text" name="posPrj" id="posPrj" tabindex="8" value="[+positioncase+]" />
               </td>
            </tr>
    
            <tr>
                <td><label for="clientname">Nom du Client : </label><br/>
                    <input type="text" name="clientname" id="clientname" tabindex="2" value="[+clientname+]" />
                </td>
            </tr>
            
            <tr>
                <td> 
                    <label for="titleTextPrj">Titre Descriptif : </label><br/>
                    <input type="text" name="titleTextPrj" id="titleTextPrj" size ="50" tabindex="3" value="[+titlecase+]" />
                </td>
    
                <td>
                    <label for="descriptif">Descriptif : </label><br/>
                    <textarea cols="47" rows="4" name="descriptif" id="descriptif" tabindex="4" >[+textcase+]</textarea>
                </td>
            </tr>
            
            <tr>
                <td> 
                <label for="typePrj">Type du projet : </label><br/>
                <input type="text" name="typePrj" id="typePrj" tabindex="5" size ="50" value="[+typecase+]" />
                </td>
                <td> 
                <label for="linkPrj">Lien du projet : </label><br/>
                <input type="text" name="linkPrj" id="linkPrj" tabindex="6" value="[+linkcase+]" />
                </td>
            </tr>
    
            <tr>
                <td> 
                <label for="titrePrj">Entête Projet : </label><br/>
                <input type="text" name="titrePrj" id="titrePrj" tabindex="7" value="[+typetitlecase+]" />
               </td>
            </tr>
    
            <tr>
                <td>
                    <p><input type="radio" id="radio_print" name="radio_cat" tabindex="5" size="1" value="print"  [+tagprint+]  onclick ="get_radio_value();" />
                    <label for="radio_print" class="checkbox">Print </label>
                      
                    <input type="radio" id="radio_web" name="radio_cat" tabindex="6" size="1" value="web"  [+tagweb+]  onclick ="get_radio_value();" />
                    <label for="radio_web" class="checkbox">Web</label>
                    </p>
                </td>
            </tr>
            <!-- Bouton Submit -->
            <tr><td><input type="submit" value="sauvegarder" name="saveBtn" class="button-submit" /></td></tr>
    </table>
    </form>
    
    


    Placeholders [+textcase+] (textarea) and [+tagprint+]/[+tagweb+] (radioBtn), are null.

    The other input values are ok.

    that’s really strange because when i return the form with a getChunk, it works correctly.
    But when i pass with eform, that doesn’t work, and all the others params are ok.

    Maybe it’s not the correct use of eform & eform2db...

    I’m to the end of my project and i’m losing time with this.

    May you please help?

    Sorry for my english smiley



      • 29774
      • 386 Posts
      I’m not sure I follow what you’re doing, but what I can tell you is that eform parses the form chunk and rebuilds the xhtml from scratch. To insert custom markup you can str_replace the placeholders directly, but for form field values just change the values held in $fields associative array. Call on eFormOnBeforeFormParse :

      function populate_form(&$fields, &$templates)
      {
         if (!count($_POST) > 0)
         {
         // get $value from database and format custom html
         $templates['tpl']=str_replace('[+my_placeholder+]', $value, $templates['tpl']);
      
         // or set field values
         $fields['my_field_name'] = $value;
         }
      }
      
      
        Snippets: GoogleMap | FileDetails | Related Plugin: SSL
        • 21702
        • 10 Posts
        hello therebechips,

        Thanks for your answer.

        In fact, yes, i just want to populate and maybe edit fields of my form before update db.
        I didn’t know the eFormOnBeforeFormParse function, and i think it’s possibly a part of the solution, i’ll try it and come back...

        thanks again !
          • 21702
          • 10 Posts
          oh,
          sorry but i can’t test your reply, i’ve got a problem to call the populate function :

          Fatal error: Call to undefined function populate_form()) in /homez.333/hypnoz/www/admin/assets/snippets/eform/eform.inc.php on line 139

          I saw a post on that http://modxcms.com/forums/index.php?topic=8572.40, but that didn’t solve the pb, is it a bug of eform ? i don’t think so ... any idea ?

          my call is like that :
          [!getCase!]
          [[updateCase2db]]
          [!eForm? &noemail=`true` &formid=`updateCaseForm` &eFormOnBeforeMailSent=`updateCase2db` &tpl=`form_edition` &thankyou=`updateFormResult` &pos=`[+positioncase+]` &clientname=`[+clientname+]` &title =`[+titlecase+]` &text=`[+textcase+]` &type=`[+typecase+]` &link=`[+linkcase+]` &typeTitle=`[+typetitlecase+]` &print=`[+tagprint+]` &web=`[+tagweb+]` &eFormOnBeforeFormParse=`populate_form`!]
            • 21702
            • 10 Posts
            I really do not understand, maybe it’s me ...

            I just put the &debug=`1` param in the eform call which display all the eForm configuration :

            all parameters are ok...

            ’eFormOnBeforeFormParse’ => ’populate_form’ is ok for that.

            The function in my eform2db is named populate_form but it don’t find my encapsuled function. I called functions in others snippets without pb ...

            Maybe i ’m wrong with the use of eform...

            May anyone help me ?



              • 5340
              • 1,624 Posts
              Is your populate_form function available in getCase or updateCase2db snippets?
              Have you un-cached your page?
                • 21702
                • 10 Posts
                Hello Cipa,

                Thanks for answering smiley

                Euh, i’m sorry, i found my error, i had encapsuled my function populate_form in the function in updateCase2db ... Sorry, i’m not really proud smiley . but it’s ok for that.

                But, if the solution with the function populate_form works good, that doesn’t solve my pb, the fields textarea and radioBtn doesn’t show anything, at the same time, all the others fields are ok...

                i put my updateCase2db code here for those who want : ( as eform2db ) :
                <?php
                function populate_form(&$fields, &$templates){
                
                   if (!count($_POST) > 0)
                   {
                         $fields['posPrj'] = $posForm;
                         $fields['clientname'] = $clientNameForm;
                         $fields['titleTextPrj'] = $titleForm ;
                         $fields['descriptif'] = $textForm ; // pb here
                         $fields['typePrj'] = $typeForm;
                         $fields['linkPrj'] = $linkForm ;
                         $fields['titrePrj'] = $titleTypeForm ;
                        
                        $templates['tpl']=str_replace('[+tagprint+]', $printTagForm, $templates['tpl']); // pb here
                        $templates['tpl']=str_replace('[+tagweb+]', $webTagForm, $templates['tpl']);     // pb here
                
                   }
                }
                
                function updateCase2db ( &$fields )
                {
                /*---------------------------------------------------------------		
                updateCase2db from eform2db ( pixelChutes )
                ---------------------------------------------------------------
                Requirements:
                eForm 1.4+
                ---------------------------------------------------------------
                
                ---------------------------------------------------------------*/
                
                // Bring needed resources into scope
                global $modx, $table_prefix;
                
                $posForm= isset($pos) ? $pos : 0;
                $clientNameForm = isset($clientName) ? $clientName : "";
                $titleForm = isset($title) ? $title : "";
                $textForm = isset($text) ? $text : ""; 
                $typeForm = isset($type) ? $type : "";
                $linkForm = isset($link) ? $link : "";
                $titleTypeForm = isset($typeTitle) ? $typeTitle : "";
                $printTagForm = isset($print) ? $print : "";
                $webTagForm = isset($web) ? $web : "";
                
                
                // Init our array
                $dbTable = array(); 
                
                
                // Insert field/value pairs to insert/update in our table
                $dbTable[position] = $posForm; //position du projet
                $dbTable[clientname] = $clientNameForm; // client Name Field
                $dbTable[title] = $titleForm; //titre text prj
                $dbTable[text] = $textForm; //descriptif
                $dbTable[projectType] = $typeForm; //type projet
                $dbTable[projectLink] = $linkForm; //lien du projet
                $dbTable[projectTypeTitle] = $titleTypeForm; //titre "projet"
                
                // radio buttons "web" / "print"
                // $printTagForm = "checked" or ""
                if ($printTagForm !=""){
                    $dbTable[tags] = $printTagForm;
                }
                elseif ($webTagForm !=""){
                    $dbTable[tags] = $webTagForm;
                }
                
                				
                // Run the db insert query
                $dbQuery = $modx->db->update( $dbTable, 'cases' );	
                
                return true;
                }
                ?>


                I’ve got the value of the textarea from Database in [!getCase!], if i put [+textcase+] juste before [!eForm ..., it show me the result correctly.
                But not in my populate_form in updateCase2db.

                I think it’s maybe because there ’s not an input "value" for textArea... I ’ll search on that

                Thx for all guys.
                  • 21702
                  • 10 Posts
                  Hello again,
                  A new day with news ideas smiley

                  yesterday, really strange, but now i solve my pb.
                  Instead of using the snippet [!getCase!] before the call of updateCase2db, i put the content of getCase in the function populate_form and it works great, all the fields of the form are ok...

                  I don’t know why the textarea fields didn’t want to work, but with the sql request in the updateCase2db, it is more simple and proper.

                  here is the code if that can help :

                  - the call in the chunk :
                                  
                  [!updateCase2db!]
                  
                  [!eForm? &noemail=`true` &formid=`updateCaseForm` &eFormOnBeforeMailSent=`updateCase2db` &eFormOnBeforeFormParse=`populate_form` &tpl=`form_edition` &thankyou=`updateFormResult` &print=`[+tagprint+]` &web=`[+tagweb+]`&idCase=`[+caseId+]!]
                  


                  <?php
                  function populate_form(&$fields, &$templates){
                     global $modx;
                  
                     if (!count($_POST) > 0)
                     {
                      $caseId = $_REQUEST["idPrj"];
                      $modx->setPlaceholder('caseId', $caseId);
                  
                      $modx->db->connect();
                      
                      $res = $modx->db->select("*", 'cases',"id='" . $caseId."'"); 
                      $irow = $modx->db->getRow($res);
                  
                      // categorie 'web' 'print'
                      if ($irow ['tags'] =="web"){
                       $web ='checked';
                       $print ="";
                      }
                      else {
                       $web ="";
                       $print ='checked';
                      }
                  
                      $caseId = $_REQUEST["idPrj"];
                      $modx->setPlaceholder('caseId', $caseId);
                  
                      $modx->setPlaceholder('tagprint', $print);
                      $modx->setPlaceholder('tagweb', $web);
                  
                      $fields['posPrj'] = mysql_escape_string($irow['position']);//$posForm;
                      $fields['clientname'] = mysql_escape_string($irow['clientname']);//$clientNameForm;
                      $fields['titleTextPrj'] =  mysql_escape_string($irow['title']);//$titleForm ;
                      //$fields['desc'] = mysql_escape_string($irow['text']);//$textForm ;
                      $fields['typePrj'] = mysql_escape_string($irow['projectType']);//$typeForm;
                      $fields['linkPrj'] = mysql_escape_string($irow['projectLink']);//$linkForm ;
                      $fields['titrePrj'] = mysql_escape_string($irow['projectTypeTitle']);//$titleTypeForm ;
                  
                      $templates['tpl']=str_replace('[+textcase+]', mysql_escape_string($irow['text']), $templates['tpl']);
                      $templates['tpl']=str_replace('[+tagprint+]', $print, $templates['tpl']);
                      $templates['tpl']=str_replace('[+tagweb+]', $web, $templates['tpl']);
                     }
                  }
                  
                  function updateCase2db ( &$fields )
                  {
                  /*---------------------------------------------------------------		
                  updateCase2db from eform2db ( pixelChutes )
                  ---------------------------------------------------------------
                  Requirements:
                  eForm 1.4+
                  ---------------------------------------------------------------
                  
                  ---------------------------------------------------------------*/
                  
                  // Bring needed resources into scope
                  global $modx, $table_prefix;
                  
                  $caseId = isset($idCase) ? $idCase: 1;
                  $printTagForm = isset($print) ? $print : "";
                  $webTagForm = isset($web) ? $web : "";
                  
                  // Init our array
                  $dbTable = array(); 
                  
                  // Insert field/value pairs to insert/update in our table
                  $dbTable[position] = $fields[posPrj]; //position du projet
                  $dbTable[clientname] = $fields[clientname]; // client Name Field
                  $dbTable[title] = $fields[titleTextPrj]; //titre text prj
                  $dbTable[text] = $fields[descriptif]; //descriptif
                  $dbTable[projectType] = $fields[typePrj]; //type projet
                  $dbTable[projectLink] = $fields[linkPrj]; //lien du projet
                  $dbTable[projectTypeTitle] = $fields[titrePrj]; //titre "projet"
                  
                  
                  $dbTable[tags] = $fields[radio_cat]; // "web" / "print"
                  
                  
                  				
                  // Run the db update query
                  $dbQuery = $modx->db->update( $dbTable, 'cases' , 'id = "' . $caseId . '"');	
                  echo $dbQuery;	
                  	
                  
                  return true;
                  }
                  ?>


                  ok, i loose 2 prod days on that little pb... ouch.

                  Thanks to therebechips who show me a part of the solution ...