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.
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
if (!function_exists("eform2db")) { // add this at the beginning /* existing eform2db() function */ function eform2db() { } } // add this a the end
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?
[[transcript2db_v2]] [!eForm? &noemail=`true` &formid=`transcriptform1` &eFormOnBeforeMailSent=`transcript2db_v2` &tpl=`transcript_form1` &thankyou=`transcriptthanks` &jScript=`http://heav.org/assets/js/datepicker.js` !]
<?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 ''; ?>
<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>