1

I have a form on a non-Joomla website which has the following fields:

  • Full Name
  • Email Address
  • Work In A Pub (Tick box)
  • Supplier (Tick box)
  • Over 18

I have the following code to send from the external form through to the Joomla database (Joomla is using RSForms to capture this exact data):

     // read form
     if(strcasecmp($_GET['method'],'subscribe') == 0){

         $fullName = $_POST['fullName'];
         $emailAddress = $_POST['emailAddress'];
         $worksInPub = ($_POST['workInPub']==='true');
         $isSupplier = ($_POST['isSupplier']==='true');
         $isOver18 = ($_POST['isOver18']==='true');

         // Do something here with the data. If it fails, modify $response['code'] accordingly

         $response['code'] = 1;

         $response['status'] = $api_response_code[ $response['code'] ]['HTTP Response'];
         $response['data'] = $api_response_code[ $response['code'] ]['Message'];

     } 

What code do I need to write to submit the above variables through to the RSForms table in the database?

If I use a sql statement then it won't have the SubmissionId in it (as this is from a different database table

1 Answer 1

1

All you need to do is write a database query. I would suggest importing the Joomla API and writing a Joomla styled query like so:

$fullName     = $_POST['fullName'];
$emailAddress = $_POST['emailAddress'];
$worksInPub   = ($_POST['workInPub']==='true');
$isSupplier   = ($_POST['isSupplier']==='true');
$isOver18     = ($_POST['isOver18']==='true');

$db = JFactory::getDbo();     
$query = $db->getQuery(true);

$columns = array('fullName', 'emailAddress', 'workInPub', 'isSupplier', 'isOver18');
$values = array($db->quote($fullName), $db->quote($emailAddress), $db->quote($workInPub), $db->quote($isSupplier), $db->quote($isOver18));

$query->insert($db->quoteName('#__rs_forms_table'))
      ->columns($db->quoteName($columns))
      ->values(implode(',', $values));

$db->setQuery($query);
$db->execute();

I have never used RSForms before so I don't know how the data for your forms is stored, so the above may be wrong. There may also be a few tweaks to make to the code, such as the database table name

2
  • IIRC, it has a table for submissions that links a unique auto-incrementing submission id to form id and some meta data. The it has a table for the actual values that is linked to the submissions table and a separate fields table that tells what the value means. Fields table is obviously also linked to the forms table. This allows editing the forms without breaking old submissions. And saves the trouble of creating new tables and other table management. There are utility functions to help when you use data within component so it isn't that bad. But it has been a while since I used this. Jan 20, 2015 at 17:49
  • You could check the save method in the admin model submissions.php and (re)use that. Jul 20, 2015 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.