We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14868
    • 17 Posts
    eform2db works great.

    1. i’m able to save my data to the database, but after the form is posted i go back to the same page without showing the updated information stored in the table. It’s not until i refresh the page that i see the updated info.

    is there a way i can have the page refresh the data between the time the form posts and the page is rendered with the updated information? am i missing something.


      • 1611
      • 591 Posts
      Is this page cachable?
        • 14779
        • 256 Posts
        Just to Clarify:

        the &eFormOnBeforeMailSent=`` param needs to contain the name of the FUNCTION from the eform2db snippet, right?
          PM me to find out how you can get a FREE ipad 2!
          • 1611
          • 591 Posts
          Yes, it’s the name of PHP function.
            • 3217
            • 6 Posts
            Good day,
            So I’ve been using eForm2db in some of my MODx forms. However, when I work with form fields with the same name (duplicated fields), is confusing to get it’s values and insert them in DB table.

            Here’s an example:
            &
            <?php function insertPensum( $fields ) {
                  global $modx, $table_prefix;
                  $tbl_carrera = $table_prefix.'carreras';
                  $tbl_catedra = $table_prefix.'catedras';
                  define('IDSTAT',1);
            
                  // Asignacion de fields para carreras
                  $dbTable = array();
            
                  $dbTable[id_carrer] = NULL;
                  $dbTable[id_stat] = IDSTAT;
                  $dbTable[id_uni] = $fields[id_uni];
                  $dbTable[carrer_descp] = $fields[carrer_descp];
            
                  // Insercion de datos en tabla de carreras
                  $dbQuery = $modx->db->insert($dbTable, $tbl_carrera); //This query works perfectly.
            
                  //Here I search the recent inserted ID.
                  $allFields = $modx->db->select('id_carrer', $tbl_carrera);
                  $rowSize = $modx->db->getRecordCount($allFields);
            
                  if($rowSize > 1) {
                      $i=1;
                      while($row = $modx->db->getRow($allFields)) {
                          $i++;
                          if($i == $rowSize) $lastID = $row['id_carrer'];
                      }
                  } elseif($rowSize == 1) {
                      $row = $modx->db->getRow($allFields);
                      $lastID = $row['id_carrer'];
                  } else echo 'No hay carreras insertadas. Por favor verifique el insert de carreras en el snippet';
            
                  //These fields are the duplicated ones. Is basicatly a form to insert 
                  $idMat = array(implode(',', $fields[id_mat]));
                  $matDesc = array(implode(',', $fields[mat_desc]));
                  $matSem = array(implode(',', $fields[mat_sem]));
                  $matCredit = array(implode(',', $fields[mat_credit]));
                  $matBasico = array(implode(',', $fields["mat_basico"]));
                  
                  $fldSize = count($idMat);//I don't know if this is right: Here I get the length of array.
            
                  for($i=0; $i <= $fldSize; $i++) {
                      if($i == ($fldSize-1)) {
                          $fldOuput .= '('.$idMat[$i].', '.IDSTAT.', '.$lastID.', `'.$matDesc[$i].'`, '.$matSem[$i].', '.$matCredit[$i].', '.$matBasico[$i].')';
                      } elseif(($i == $fldSize) || (!$idMat[$i])) {
                          $fldOuput .= '';
                      } else $fldOuput .= '('.$idMat[$i].', '.IDSTAT.', '.$lastID.', `'.$matDesc[$i].'`, '.$matSem[$i].', '.$matCredit[$i].', '.$matBasico[$i].'), ';
                  }
            
                  //Inserte the data in the table
                  $dbQuery = $modx->db->query('INSERT INTO '.$tbl_catedra.' (id_mat, id_stat, id_carrer, mat_desc, mat_sem, mat_credit, mat_basico) VALUES '.$fldOuput);
            
                  return true;
            }
            ?>


            The following is the error MODx gives back, when I tried to submit 2 subjects:

            « MODx Parse Error »
            MODx encountered the following error while attempting to parse the requested resource:
            « Execution of a query to the database failed - Column count doesn’t match value count at row 1 »
            SQL: INSERT INTO ugmodx_catedras (id_mat, id_stat, id_carrer, mat_desc, mat_sem, mat_credit, mat_basico) VALUES (12001114,12001213, 1, 2, `Matemática I,Computación Básica I`, 1,1, 4,3, 1)

            The form chunk. I duplicate the fields by the jQuery append function:
                        <h2>Nuevo pensum</h2>
                        <form method="post" action="[~[*id*]~]" id="newPensum" name="newPensum">
                            <fieldset>
                                <h4>Sede y carrera</h4>
                                <input name="newPensum" type="hidden" value="NewPensum" />
                                <div id="Labels"><label for="id_uni">Sede:</label></div>
                                <select name="id_uni" id="id_uni" tabindex="0" eform="Sede::1:Eliga una sede de la carrera:#SELECT id_uni FROM {PREFIX}sedes WHERE id_stat=1">
            			[[getUni2Options]]
                                </select><br />
                                <div id="Labels"><label for="carrer_descp">Carrera:</label></div>
                                <input type="text" name="carrer_descp" id="carrer_descp" size="40" tabindex="1" eform="Carrera:string:1:Los numeros y simbolos no son aceptados:" /><br />
                                <hr />
                                <h4>Catedras</h4>
                                <table cellpadding="0" cellspacing="0" id="Catedras">
                                    <tr>
                                        <th><label for="id_mat[]">Código</label></th>
                                        <th><label for="mat_basico[]">Básica</label></th>
                                        <th><label for="mat_desc[]">Catedra</label></th>
                                        <th><label for="mat_sem[]">Semestre</label></th>
                                        <th><label for="mat_credit[]">Créditos</label></th>
                                    </tr>
                                    <tr id=\"Catedra\">
                                        <td><input type="text" name="id_mat[]" id="id_mat" size="10" maxlength="10" tabindex="2" eform="Cod. Catedra:string:1:Solo numeros aceptados:" /></td>
                                        <td><input type="checkbox" name="mat_basico[]" id="mat_basico" value="1" tabindex="3" /></td>
                                        <td>
                                            <input type="text" name="mat_desc[]" id="mat_desc" size="25" tabindex="4" eform="Catedra:string:1:Simbolos especiales no aceptados:" />
                                        </td>
                                        <td><input type="text" name="mat_sem[]" id="mat_sem" size="5" maxlength="2" tabindex="5" eform="Semestre:string:1:Letras y simbolos no son aceptados:" /></td>
                                        <td><input type="text" name="mat_credit[]" id="mat_credit" size="5" maxlength="2" tabindex="6" eform="Creditos:string:1:Letras y simbolos no son aceptados:" /></td>
                                    </tr>
                                </table>
                            </fieldset>
                            <span><a href="#" onclick="return false;" id="otraCatedra">Añadir Catedra</a></span>
                            <input name="Reset" type="reset" value="Cancelar" />
                            <input name="Submit" type="submit" value="Aceptar" />
                        </form>
              • 25441
              • 60 Posts
              Quote from: sarah at Mar 09, 2008, 11:11 PM

              Hi,

              I’ve just installed this snippet and I get this error:


              Fatal error: Call to undefined function: eform2db() in E:\hshome\arterial\arterial.com.au\microsite\assets\snippets\eform\eform.inc.php on line 386

              Does anyone know how to fix this?

              Thanks!


              Sarah

              Hello,
              have you resolve this problem?

              I ask, because i’ve the same problem too.
              • The snippet containing the eForm2db function has to be called before the eForm snippet is called.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                • Quote from: sottwell at Feb 02, 2010, 09:07 PM

                  The snippet containing the eForm2db function has to be called before the eForm snippet is called.

                  Also, with the newer versions of eForm, you can just use eForm’s runSnippet option:

                  [!eform2db_snippet!]
                  [!eForm? &eFormOnBeforeMailSent=`eform2db` ... !]

                  would become:
                  [!eForm? &runSnippet=`eform2db_snippet` &eFormOnBeforeMailSent=`eform2db` ... !]


                  As sottwell mentioned, this method will ensure that the snippet containing the eForm2db function is called in the correct order.
                    Mike Reid - www.pixelchutes.com
                    MODx Ambassador / Contributor
                    [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                    ________________________________
                    Where every pixel matters.
                    • 28972
                    • 19 Posts
                    May be I’m missing something, but are BOTH actions - (1)writing in database and (2)send notification by email is activated in this snippet?

                    Second question - In my form I need file upload field. Is it possible in eForm2db? If no, how to integrate this two function?
                    Thank you.
                      • 23849
                      • 223 Posts
                      I’ve got checkboxes in my form. When it saves the form data into the DB it just prints the word "ARRAY". How do you save the array of info from a form with checkboxes?
                        Nick Hoag
                        Creative Partner
                        The FutureForward

                        http://thefutureforward.com