pretty new to drupal and I am running into a problem trying to insert data into my database from a form.
The form itself is generated from js in my theme folder,
$ ('.register') .find('.title_block') .addClass('reg-details') .append('<div id="emailRegister" class="modal"><div class="modal-content"> <span class="close">×</span><br><br><p>We have detected that you are on a mobile device. It can take up to 2 minutes to fill out the required profile.</p><p>If you would like to finish this profile at a later time, we can email it to you.</p><p>Otherwise, select Close to proceed!</p> <form method="post" action="/register.php" enctype="multipart/form- data">First name:<br><input type="text" class="emailFields" name="firstname" value=""><br>Last name:<br><input type="text" class="emailFields" name="lastname" value=""><br>Email:<br><input type="email" class="emailFields" id="regEmail" name="email"><br><input type="submit" value="Submit"><br> </form><button type="submit" id="closeModal" style="background:grey">Close</button>') .insertBefore('.lms-main-container');
The action page is in the root of my folder
<?php require 'vendor/autoload.php'; use Drupal\docebo_login\FormaNotification; $ email = $ fname = $ lname = ""; $ email = $ _POST["email"]; $ fname = $ _POST["firstname"]; $ lname = $ _POST["lastname"]; if ($ email == "" || $ fname == "" || $ lname == "") { header("Location: http://example.com"); exit(); } $ noti = new FormaNotification(); $ result = $ noti->getRegister($ fname, $ lname, $ email); $ auth = array('api_key' => 'some=key=here'); # The unique identifier for this smart email $ smart_email_id = 'email-id'; # Create a new mailer and define your message $ wrap = new CS_REST_Transactional_SmartEmail($ smart_email_id, $ auth); $ message = array( "To" => $ email, "Data" => array( 'variableName' => 'variableNameTestValue', 'x-apple-data-detectors' => 'x-apple-data-detectorsTestValue', 'href^="tel"' => 'href^="tel"TestValue', 'href^="sms"' => 'href^="sms"TestValue', 'owa' => 'owaTestValue', 'role=section' => 'role=sectionTestValue', 'style*="font-size:1px"' => 'style*="font-size:1px"TestValue', ), ); # Add consent to track value $ consent_to_track = 'no'; # Valid: 'yes', 'no', 'unchanged' # Send the message and save the response $ result = $ wrap->send($ message, $ consent_to_track); if ($ result) { header("Location: /"); exit(); }
As you can see I call a function from my theme’s modules here is the function
public function getRegister($ fname, $ lname, $ email) { return parent::insertRegister($ fname, $ lname, $ email); }
Which Then passes the variables on to this function in its parent
public function insertRegister($ fname, $ lname, $ email) { db_set_active('docebo'); $ this->setConnection('dev-db'); $ result = $ this->getConnection()->insert('register') ->fields([ 'fistName' => $ fname, 'lastName' => $ lname, 'email' => $ email, 'dateAdded' => REQUEST_TIME, ]) ->execute(); db_set_active(); }
Now I could be naive but I thought that would be it. But When I submit the form all I get is an 500 error notice. When I remove the insert from the form action, the form works as expected.
I tried getting a better error message to help me out ie checking my settings.php to make sure error reporting was on verbose, even tring to set it in my ini.php or putting the
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
on the form action page itself and still get nothing. There also appears to be nothing in my logs as well. So I am pretty stumped. Any help at all would be greatly appreciated. Thank you!!!