We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14779
    • 256 Posts
    Can someone post an example of the code necessary to connecting to an external database server? I’ve looked at the articles on the DB API, and I’ve read this thread, but I don’t understand the required code.

      PM me to find out how you can get a FREE ipad 2!
    • Quote from: joshlfisher at Jun 07, 2010, 11:09 AM

      Can someone post an example of the code necessary to connecting to an external database server? I’ve looked at the articles on the DB API, and I’ve read this thread, but I don’t understand the required code.

      http://wiki.modxcms.com/index.php/Access_another_database_from_MODx
        Mike Reid - www.pixelchutes.com
        MODx Ambassador / Contributor
        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
        ________________________________
        Where every pixel matters.
        • 25441
        • 60 Posts
        Quote from: hugofrosch at Apr 09, 2008, 10:04 AM

        Hello, I am having quite a strange problem.
        I implemented the eform2db locally and it works fine.
        Then I copied all the nescessary files online and set up the database-table the same way as on the local system.
        Whey i try to open the file with the form I get the following error-Message:


        Fatal error: Cannot redeclare eform2db() (previously declared in /homepages/4/*****/htdocs/*****/manager/includes/document.parser.class.inc.php(769) : eval()’d code:2) in /homepages/4/*****/htdocs/*****/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 2

        Here is the code I use to call the form:

        [[eForm2db]]
        [!eForm? &noemail=`true` &formid=`registrierung` &eFormOnBeforeMailSent=`eForm2db` &tpl=`registrierung_formular` &thankyou=`registrierung_danke` !]

        I´ll be gratefull for any idea.

        Thank you,

        Henry

        Do you resolve this error?
        I have the same error
          • 3749
          • 24,544 Posts
          That usually means that the eform2db() function is being included twice on the same page.

          One solution is to find the eform2db() function and wrap it with a test so that it is only processed once (you will only be adding the first line and the last line with just the closing brace):

          if (!function_exists("eform2db")) {  // add this at the beginning
          
              /* existing eform2db() function */
              function eform2db() {
                  
              }
          
          }  // add this a the end
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • Can someone tell me how to stop a form from being sent to the DB if it’s not being validated by eform? I cannot figure out how to stop the info being sent to the DB if eform fields are empty and says to fill them out, it’s still being sent to the DB. Also if the form has been submitted and you try again, you get the message saying the form was already but the info is sent to the DB again.

            Any suggestions?
              Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
              AugmentBLU - MODX Partner

              BLUcart - MODX Revolution E-Commerce & Shopping Cart
            • Quote from: rossco at Aug 17, 2010, 04:07 PM

              Can someone tell me how to stop a form from being sent to the DB if it’s not being validated by eform? I cannot figure out how to stop the info being sent to the DB if eform fields are empty and says to fill them out, it’s still being sent to the DB. Also if the form has been submitted and you try again, you get the message saying the form was already but the info is sent to the DB again.

              Any suggestions?

              Yes, just associate the eForm2db with the correct eForm event. I would recommend eFormOnMailSent, since the function is called after the form has been validated and all templates have been parsed. I also believe this event will NOT get triggered from a duplicate form post, but please test this to be certain.

              You can review the full eForm docs directly from your MODx Evo site: http://yourdomain.com/assets/snippets/eform/docs/eform.htm

              Event Functions:

              The eForm event functions are now incorporated into the parameters. They are:

              * &eFormOnBeforeMailSent (optional)
              Expects a function name. This function will be called after the form has been validated and before the report and thankyou templates have been parsed and any emails have been sent out. See this example on how to use the events.

              * &eFormOnMailSent (optional)
              Expects a function name. This function is called after all templates have been parsed and any emails were sent.

              * &eformOnBeforeFormParse (optional)
              Expects a function name. The function is called after the templates are loaded and the formid is found valid. The function should accomodate the following parameter: &$templates - (as reference) an associative array of loaded templates with indexes ’tpl’, ’report’,’thankyou’ & ’autotext’. Be aware that the latter three will only have a value if the form has been posted!

              * &eFormOnBeforeFormMerge (optional)
              Expects a function name. This function will only be called whenever the form is displayed and just before all placeholders are merged. The function should accomodate the following parameter: &$fields - (as reference) an associative array of field and placeholder values.

              * &eFormOnValidate (optional)
              Expects a function name. This function will be called directly after the form validation has taken place. You can use this event to add your own extra validation logic. The function should accomodate the following parameters
              o &$fields - (as reference) an associative array of field and placeholder values.
              o &$vMsg - (as reference) a numeric array of validation error messages.
              o &$rMsg - (as Reference) a numeric array of missing required fields.
                Mike Reid - www.pixelchutes.com
                MODx Ambassador / Contributor
                [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                ________________________________
                Where every pixel matters.
              • Good show Pixelchutes, that works perfectly. I spent a while trying to solve this and within 2 minutes it’s fixed ha!

                Thanks a lot.

                Ross
                  Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                  AugmentBLU - MODX Partner

                  BLUcart - MODX Revolution E-Commerce & Shopping Cart
                  • 14779
                  • 256 Posts
                  If someone can show me if there is an obvious problem here, I’d appreciate it!
                  I’m trying to use eform to post a form to a database outside the modx database server.
                  Table named master does exist. The table has all columns defined. Note this database does not exist on the same server as the modx install.

                  Page looks like this:

                  [[transcript2db_v2]]
                  
                  [!eForm? &noemail=`true` &formid=`transcriptform1` &eFormOnBeforeMailSent=`transcript2db_v2` &tpl=`transcript_form1` &thankyou=`transcriptthanks` &jScript=`http://heav.org/assets/js/datepicker.js` !]


                  Link to page:
                  http://www.heav.org/other/sandbox/transcript-form-test-k.html

                  transcript2db_v2 script:
                  <?php
                  function transcript2db( &$fields )
                  	{
                  	        // Database connection Info;
                                  $host = '********';  
                                  $database = '*******';   
                                  $uid = '*****'; 
                                  $pwd = '****';  
                                  $db = new DBAPI($host,$database, $uid,$pwd);
                  
                                  $ds = $db->select('*','master');
                  	
                  		// Bring needed resources into scope
                  		// global $modx, $table_prefix;
                  
                                  $dbTable = array();
                  
                                            $dbTable['child_first_name'] = $fields['student_name_first'];
                  			  $dbTable['child_middle_name'] = $fields['student_name_middle'];
                  			  $dbTable['child_last_name'] = $fields['student_name_last'];
                  			  $dbTable['child_gender'] = $fields['student_gender'];
                  			  $dbTable['child_dob'] = $fields['student_DOB'];
                  			  $dbTable['parent_first_name'] = $fields['parent_name_first'];
                  			  $dbTable['parent_last_name'] = $fields['parent_name_last'];
                  
                  			  $dbTable['address1'] = $fields['parent_address1'];
                  			  $dbTable['address2'] = $fields['parent_address2'];
                  			  $dbTable['city'] = $fields['parent_city'];
                  			  $dbTable['state'] = $fields['parent_state'];
                  			  $dbTable['zip'] = $fields['parent_zip'];
                  			  $dbTable['phone'] = $fields['parent_phone'];
                  			  $dbTable['email'] = $fields['parent_email'];
                  			  $dbTable['child_first_name'] = $fields['student_name_first'];
                  			  $dbTable['child_middle_name'] = $fields['student_name_middle'];
                  			  $dbTable['child_last_name'] = $fields['student_name_last'];
                  			  $dbTable['child_gender'] = $fields['student_gender'];
                  			  $dbTable['child_dob'] = $fields['student_DOB'];
                  			  $dbTable['PSAT'] = $fields['student_psat_score'];
                  			  $dbTable['ACT'] = $fields['student_act_score'];
                  			  $dbTable['SAT'] = $fields['student_sat_score'];
                  			  $dbTable['GPA'] = $fields['student_gpa'];
                  			  $dbTable['totalCredits'] = $fields['total_credits'];
                  			  $dbTable['graduationDate'] = $fields['student_DOG'];
                  			  $dbTable['student_note'] = $fields['student_note'];
                  			  
                                            for( $i=9; $i<13; ++$i)
                                            {
                                              // forced two-digit grade
                                              $gr = ($i==9)?'0'.$i:$i;
                  
                                              // year grade began and ended
                     			    $dbTable['grade'.$gr.'_year_begin'] = $fields['grade'.$gr.'_fall_year'];
                  			    $dbTable['grade'.$gr.'_year_end'] = $fields['grade'.$gr.'_spring_year'];
                  
                                              // class names for the active grade
                                              for( $j=1; $j<12; ++$j)
                                              {
                                                $cn = ($j<10)?'0'.$j:$j;
                    			      $dbTable['grade'.$gr.'_cls'.$cn.'_name'] = $fields['student_grade'.$gr.'_sem01_course'.$cn.'_name'];
                                              }
                  
                                              // class score summaries
                                             for( $k=1; $k<12; ++$k )
                                             {
                                               $classNum = ($k<10)?'0'.$k:$k;
                                               $dbTable['grade'.$gr.'_cls'.$classNum .'_sem01_grade'] = $fields['student_grade'.$gr.'_sem01_course'.$classNum .'_grade'];
                  			     $dbTable['grade'.$gr.'_cls'.$classNum .'_sem02_grade'] = $fields['student_grade'.$gr.'_sem02_course'.$classNum .'_grade'];
                  			     $dbTable['grade'.$gr.'_cls'.$classNum .'_final_grade'] = $fields['student_grade'.$gr.'_course'.$classNum .'_finalgrade'];
                  			     $dbTable['grade'.$gr.'_cls'.$classNum .'_final_points'] = $fields['student_grade'.$gr.'_course'.$classNum .'_points'];
                  			     $dbTable['grade'.$gr.'_cls'.$classNum .'_final_credits'] = $fields['student_grade'.$gr.'_course'.$classNum .'_credits'];
                                             }
                  
                                            // grade score summaries
                  			  $dbTable['grade'.$gr.'_final_points'] = $fields['student_grade'.$gr.'_current_year_GPA'];
                  			  $dbTable['grade'.$gr.'_final_credits'] = $fields['student_grade'.$gr.'_current_year_credits'];
                                          }
                  			  
                  			  //START SHIPPING INFO
                  			  
                  			  $dbTable['shipping_destination'] = $fields['shipping_name'];
                  			  $dbTable['shipping_address1'] = $fields['shipping_address'];
                  			  $dbTable['shipping_address2'] = $fields['shipping_address_line2'];
                  			  $dbTable['shipping_city'] = $fields['shipping_city'];
                  			  $dbTable['shipping_state'] = $fields['shipping_state'];
                  			  $dbTable['shipping_zip'] = $fields['shipping_zip'];
                  			  $dbTable['shipping_note'] = $fields['shipping_note'];
                  			  
                  			  //END SHIPPING INFO
                   
                        // Run the db insert query
                   
                        $dbQuery = $modx->db->insert( $dbTable, 'master' );
                  
                  		return true;
                  	}
                  	// Return empty string
                  	return '';
                  ?>

                    PM me to find out how you can get a FREE ipad 2!
                    • 14779
                    • 256 Posts
                    and to continue....


                    form html:
                    <form id="form1" name="transcriptform1" method="post" action="">
                        <input type="hidden" name="formid" value="transcriptform1" />
                        <table width="600">
                            <tr>
                                <td>
                                    <h1 align="center">HEAV’s Online Transcript Input Screen</h1>
                                    <p>Please enter the information off your Transcript Worksheet into the appropriate fields below. Fields with a * are required.        </p>
                                    <p>
                                        <b>Reordering a transcript? </b>
                                        If you’ve already input your data and just need another copy of your transcript, please 
                                        <a href="[~3119~]">click here.</a></p></td></tr><tr><td> </td></tr></table>
                        <table><tr><td style="vertical-align:top">
                                    <fieldset><b><legend>Student Information                </legend></b>
                                        <table><tr><td><fieldset>
                                                        <i><legend>Student's Name</legend></i>
                                                        <table>
                                                            <tr><td><label>First:</label></td>
                                                                <td><input name="student_name_first" type="text" size="20" maxlength="100" eform="Student's First Name::1:"/></td></tr>
                                                            <tr><td><label>Middle:</label></td>
                                                                <td><input name="student_name_middle" type="text" size="20" maxlength="100" eform="Student's Middle Name::1:"/></td>
                                                            <tr><td><label>Last:</label></td>
                                                                <td><input name="student_name_last" type="text" size="20" maxlength="100" eform="Student's Last Name::1:"/></td></tr>
                                                        </table></fieldset></td></tr>
                                            <tr><td><table><tr>
                                                            <td><label>Gender:</label></td>
                                                            <td><select name="student_gender">
                                                                    <option selected="selected" value=" ">Please Select:</option>
                                                                    <option value="Male">Male</option>
                                                                    <option value="Female">Female</option>
                                                                </select></td></tr>
                                            <tr>
                                                <td valign="top"><label>Birth:</label></td>
                                                <td><input id="student_DOB" name="student_DOB" type="text" size="15" maxlength="10"
                                                    eform="Student's Date of Birth:date:1:#EVAL return (strtotime($value)!==-1)?true:false;"/>
                                                    <a href="javascript:NewCal('student_DOB','ddmmyyyy');"> 
                                                        <img src="http://heav.org/assets/images/cal.gif" width="16" height="16" border="0" alt="Pick a date" />
                                                    </a></td></tr></table></td></tr></table>
                                    <fieldset>
                                        <i><legend>Parent(s)'s Name</legend></i>
                                        <table>
                                            <tr><td><label>First Name (s):</label></td>
                                                <td><input name="parent_name_first" type="text" size="20" maxlength="100"
                                                    eform="Parent's First Name::1:"/></td></tr>
                                            <tr><td><label>Last Name:</label></td>
                                                <td><input name="parent_name_last" type="text" size="20" maxlength="100"
                                                    eform="Parent's Last Name::1:"/></td></tr></table></fieldset></fieldset></td>
                                <td style="vertical-align:top">
                                    <fieldset>
                                        <b><legend>Scoring Information</legend></b>
                                        <table>
                                            <tr><td><label>PSAT:</label></td>
                                                <td><input name="student_psat_score" type="text" size="5" maxlength="5" /></td></tr>
                                            <tr><td><label>ACT:</label></td>
                                                <td><input name="student_act_score" type="text" size="5" maxlength="5" /></td></tr>
                                            <tr><td><label>SAT:</label></td>
                                                <td><input name="student_sat_score" type="text" size="5" maxlength="5" /></td></tr>
                                            <tr><td><label>CUM GPA:</label></td>
                                                <td><input name="student_gpa" type="text" size="5" maxlength="5" /></td></tr>
                                            <tr><td><label>Credits:</label></td>
                                                <td><input name="total_credits" type="text" size="5" maxlength="5" /></td></tr>
                                            <tr><td><label>Graduation Date:</label></td>
                                                <td>
                                                    <input id="student_DOG" name="student_DOG" type="text" size="5" maxlength="12"
                                                        eform="Students Graduation Date:date:1:#EVAL return (strtotime($value)!==-1)?true:false;"/>
                                                        <a href="javascript:NewCal('student_DOG','mmddyyyy');">
                                                            <img src="http://heav.org/assets/images/cal.gif" width="16" height="16" border="0" alt="Pick a date" />
                                                        </a></tr></table></fieldset></td></tr></table>
                        <table width="600" >
                            <tr>
                                <td>
                                    <fieldset>
                                        <b><legend>Student's Address and Contact Information                </legend></b>
                                        <table>
                                            <tr><td colspan="6">
                                                <i>The address will appear on the transcript; the e-mail and phone number <br /> are so we can contact you if we have questions.</i></td></tr>
                                            <tr><td width="84" ><label>Address:</label></td>
                                                <td colspan="2" ><input type="text" name="parent_address1" size="23" maxlength="100" eform="Address::1:" />*</td>
                                                <td width="41" ><label>E-mail:</label></td>
                                                <td width="253"  colspan="2"><input name="parent_email" type="text" size="22" maxlength="100" eform="E-mail:email:1:" />*</td></tr>
                                            <tr><td></td>
                                                <td colspan="2"><input type="text" name="parent_address2" size="23" maxlength="100" /></td>
                                                <td><label>Phone:</label></td>
                                                <td colspan="2"><input name="parent_phone" type="text" size="22" maxlength="100" /></td></tr>
                                            <tr><td><label>City:</label></td>
                                                <td colspan="2"><input type="text" name="parent_city" size="23" maxlength="100" eform="City::1:" />*</td></tr>
                                            <tr ><td ><label>State:</label></td>
                                                <td colspan="4"><select name="parent_state" eform="Select State::1">
                                                        <option value="AL">AL</option>
                                                        <option value="AK">AK</option>
                                                        <option value="AZ">AZ</option>
                                                        <option value="AR">AR</option>
                                                        <option value="CA">CA</option>
                                                        <option value="CO">CO</option>
                                                        <option value="CT">CT</option>
                                                        <option value="DE">DE</option>
                                                        <option value="DC">DC</option>
                                                        <option value="FL">FL</option>
                                                        <option value="GA">GA</option>
                                                        <option value="HI">HI</option>
                                                        <option value="ID">ID</option>
                                                        <option value="IL">IL</option>
                                                        <option value="IN">IN</option>
                                                        <option value="IA">IA</option>
                                                        <option value="KS">KS</option>
                                                        <option value="KY">KY</option>
                                                        <option value="LA">LA</option>
                                                        <option value="ME">ME</option>
                                                        <option value="MD">MD</option>
                                                        <option value="MA">MA</option>
                                                        <option value="MI">MI</option>
                                                        <option value="MN">MN</option>
                                                        <option value="MS">MS</option>
                                                        <option value="MO">MO</option>
                                                        <option value="MT">MT</option>
                                                        <option value="NE">NE</option>
                                                        <option value="NV">NV</option>
                                                        <option value="NH">NH</option>
                                                        <option value="NJ">NJ</option>
                                                        <option value="NM">NM</option>
                                                        <option value="NY">NY</option>
                                                        <option value="NC">NC</option>
                                                        <option value="ND">ND</option>
                                                        <option value="OH">OH</option>
                                                        <option value="OK">OK</option>
                                                        <option value="OR">OR</option>
                                                        <option value="PA">PA</option>
                                                        <option value="RI">RI</option>
                                                        <option value="SC">SC</option>
                                                        <option value="SD">SD</option>
                                                        <option value="TN">TN</option>
                                                        <option value="TX">TX</option>
                                                        <option value="UT">UT</option>
                                                        <option value="VT">VT</option>
                                                        <option value="VA" selected="selected">VA</option>
                                                        <option value="WA">WA</option>
                                                        <option value="WV">WV</option>
                                                        <option value="WI">WI</option>
                                                        <option value="WY">WY</option>
                                                    </select>* 
                                                    <input name="parent_zip" type="text" size="5" maxlength="5" eform="Zipcode::1:" />*
                                                </td></tr></table></fieldset></td></tr></table>
                      
                            </fieldset>
                              </td></tr></table>
                    <table width="600"><tr><td>  <p><b>Important! </b>Before you submit this form, please <strong><span class="red">carefully spell check and verify the accuracy</span></strong> the information inputted above. We suggest copying text over to Word to spell check and guard against typos. The form does NOT spell check, and once you click submit below, you will not be able to make any changes to the transcript.</p>
                               <p>
                                 <input name="checkbox" type="checkbox" id="checkbox" value="agreed" eform="Yes, I have carefully checked all the information.::1:"/>
                      <b>Yes, I have carefully checked all the information for spelling and accuracy errors.</b> I understand that HEAV is not responsible for the accuracy of any information submitted and that the transcript information will be printed exactly as typed above. </p></td></tr></table>
                      <div align="left">
                    <input type="submit" name="Add" value="Submit" />
                              <input type="submit" name="Reset" value="Reset" />
                      </div>
                          </form>
                    
                      PM me to find out how you can get a FREE ipad 2!
                      • 4080
                      • 139 Posts
                      It looks like eForm2db 0.1 [Beta] (most current release?) isn’t in the repository. For 1.0.4 do I just need the original code in this thread (0.1 beta from pixelchutes) and/or the little tutorial here?: http://wiki.modxcms.com/index.php/Use_eForm_to_Store_data_into_Database. I know this thread goes back quite a few years.

                      Thanks in advance.