• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Edit article after submission

Edit article after submission 3 years 9 months ago #41306

  • mkonop
  • mkonop's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
An article is created when a form is submitted. If a user edits the data, it only changes RSForm submissions, not the article. Is there a way for a user to edit or resubmit their form data that would change the article too?
The administrator has disabled public write access.

Edit article after submission 3 years 9 months ago #41322

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 745
  • Thank you received: 66
Hello,

Well, the Submissions Directory menu item that allows users to edit their submissions only affects the information from the component specific database tables, for your described scenario you will need to use a custom script that will also update the correct article when the user edits his submission.

In order to do this you can use the Scripting area available for emails, PHP Email Scripts. In order for this to be triggered you will need to also have an email notification configured for the directory.
www.rsjoomla.com/support/documentation/r...ctory-menu-item.html

Have a nice day!
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.
The following user(s) said Thank You: mkonop

Edit article after submission 3 years 9 months ago #41329

  • mkonop
  • mkonop's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Hi again,
Would you happen to have an example of a script that I can modify for my use? Thanks again.
The administrator has disabled public write access.

Edit article after submission 3 years 9 months ago #41369

I would be interested in that too!!
The administrator has disabled public write access.

Edit article after submission 3 months 1 week ago #43818

  • huwhuw
  • huwhuw's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 1
Hi i wrote this but its not updating the article from editing the directory?
defined('_JEXEC') or die;
 
use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table;
 
try {
    // Log that the script was triggered
    Factory::getApplication()->enqueueMessage('Submission update script triggered!', 'info');
 
    $db = Factory::getContainer()->get('DatabaseDriver');
 
    // Extract SubmissionId
    $submissionId = (int) $submission->SubmissionId;
 
    // Fetch the latest submission values from josrh_rsform_submission_values
    $query = $db->getQuery(true)
        ->select($db->quoteName(['FieldName', 'FieldValue']))
        ->from($db->quoteName('josrh_rsform_submission_values'))
        ->where($db->quoteName('SubmissionId') . ' = ' . $submissionId);
    $db->setQuery($query);
    $rawValues = $db->loadObjectList('FieldName');
 
    if (!$rawValues) {
        throw new Exception('Failed to fetch submission data for ID: ' . $submissionId);
    }
 
    // Map submission values to an array for easy access
    $submissionValues = [];
    foreach ($rawValues as $fieldName => $fieldObject) {
        $submissionValues[$fieldName] = $fieldObject->FieldValue;
    }
 
    // Extract ArticleId
    $articleId = isset($submissionValues['ArticleId']) ? (int) $submissionValues['ArticleId'] : 0;
 
    // Check if the ArticleId is valid
    if (!$articleId) {
        Factory::getApplication()->enqueueMessage('No ArticleId found in the submission.', 'error');
        return;
    }
 
    // Map fields to josrh_content
    $articleData = [
        'id' => $articleId, // Primary key
        'title' => $submissionValues['Title'], // Title of the article
        'introtext' => $submissionValues['Description'], // Intro text
        'catid' => (int) $submissionValues['Category'], // Category ID
        'modified' => Factory::getDate()->toSql(), // Update modified date
        'modified_by' => Factory::getUser()->id, // User making the change
    ];
 
    // Load and update the article
    $article = Table::getInstance('Content', 'JTable');
    if (!$article->load($articleId)) {
        Factory::getApplication()->enqueueMessage('No article found with ID: ' . $articleId, 'error');
        return;
    }
 
    $article->bind($articleData);
 
    // Validate and save the article
    if (!$article->check() || !$article->store()) {
        throw new Exception('Error updating article: ' . $article->getError());
    }
 
    Factory::getApplication()->enqueueMessage('Article updated successfully! Article ID: ' . $articleId, 'success');
 
    // Map fields to josrh_fields_values
    $customFields = [
        'email' => $submissionValues['Email'],
        'phone' => $submissionValues['Phone'],
        'locationaddress' => $submissionValues['Address'],
        'google-map-coordinates' => $submissionValues['Google_Map_Coordinates'],
        'website-booking-link' => $submissionValues['Booking_Link'],
        'eircode' => $submissionValues['Eircode']
    ];
 
    foreach ($customFields as $fieldName => $fieldValue) {
        // Get the field ID for the custom field
        $fieldQuery = $db->getQuery(true)
            ->select($db->quoteName('id'))
            ->from($db->quoteName('josrh_fields'))
            ->where($db->quoteName('name') . ' = ' . $db->quote($fieldName));
        $db->setQuery($fieldQuery);
        $fieldId = $db->loadResult();
 
        if (!$fieldId) {
            Factory::getApplication()->enqueueMessage('Custom field not found: ' . $fieldName, 'warning');
            continue;
        }
 
        // Check if a value exists for this field and article
        $valueQuery = $db->getQuery(true)
            ->select($db->quoteName('field_id'))
            ->from($db->quoteName('josrh_fields_values'))
            ->where($db->quoteName('field_id') . ' = ' . (int) $fieldId)
            ->where($db->quoteName('item_id') . ' = ' . (int) $articleId);
        $db->setQuery($valueQuery);
        $fieldValueExists = $db->loadResult();
 
        if ($fieldValueExists) {
            // Update the existing field value
            $updateQuery = $db->getQuery(true)
                ->update($db->quoteName('josrh_fields_values'))
                ->set($db->quoteName('value') . ' = ' . $db->quote($fieldValue))
                ->where($db->quoteName('field_id') . ' = ' . (int) $fieldId)
                ->where($db->quoteName('item_id') . ' = ' . (int) $articleId);
            $db->setQuery($updateQuery);
            $db->execute();
        } else {
            // Insert a new field value
            $insertQuery = $db->getQuery(true)
                ->insert($db->quoteName('josrh_fields_values'))
                ->columns(['field_id', 'item_id', 'value'])
                ->values((int) $fieldId . ', ' . (int) $articleId . ', ' . $db->quote($fieldValue));
            $db->setQuery($insertQuery);
            $db->execute();
        }
    }
 
    Factory::getApplication()->enqueueMessage('Custom fields updated successfully!', 'success');
} catch (Exception $e) {
    // Log errors
    Factory::getApplication()->enqueueMessage('Error in submission update script: ' . $e->getMessage(), 'error');
}
 
I set the title from "My Hotel" to "My Hotel 2" in RS Forms Directory
Then i save
Joomla article title stays the same.
I set the title from "My Hotel 2" to "My Hotel X" in RS Forms Directory
I save again.
Joomla article title now changes to "My Hotel 2".
I set the title from "My Hotel X" to "My Hotel Y" in RS Forms Directory
I save again.
Joomla article title now changes to "My Hotel X".
So its always one step behind

Any ideas please
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!