Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Is there a beforeSurveySubmit event similar to afterSurveyComplete?

  • srinivaskaundinya
  • srinivaskaundinya's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago - 3 years 5 months ago #206460 by srinivaskaundinya
Background: As of now we have a plugin which listens to afterSurveyComplete event and calls a REST API once a survey is Submitted. If the REST service is down when I submitted the survey, survey will be submitted successfully in Limesurvey but it fails to reach the REST API. If a user try to access the same survey again, it shows invitation is expired(we are using closed survey).

I need to call a REST API once a user submits a survey, and validate whether the REST service is up. If the service is up then only I want the survey should to be submitted in Limesurvey else survey should not be submitted(user can come and submit it later as the invitation will not be expired).

I tried validating it using Javascript(continue submitting the survey it if the service is up else return false and stop the survey from getting submitted) but it's not feasible because of CORS.

In case of afterSurveyComplete event, I can't stop the survey getting submitted as the event will be triggered only after the survey is submitted successfully. Is there an event which gets triggered before submitting the survey? so that I can stop the survey getting submitted and return a message to user to resubmit it?
Last edit: 3 years 5 months ago by srinivaskaundinya. Reason: Updated the content
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #206509 by DenisChenu
With a simple survey : maybe you can check if App()->getRequest()->getPost('move') == 'submit in beforeSurveyPage.
But seems complex after …

Why not 'reset' to unsubmitted the current reponse ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • srinivaskaundinya
  • srinivaskaundinya's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #206512 by srinivaskaundinya
Thank you for your valuable feedback.
Is it possible to reset the current response through remote control API or any other way programatically with out manually changing it through UI?

If I reset to unsubmitted, the survey answers has to be re-entered or the entered answers will be still present(just like save and resume)?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #206513 by DenisChenu
No ,

My idea (quick with surely some syntax error).

Code:
$surveyId   = $this->getEvent()->get('surveyId');
    $responseId = $this->getEvent()->get('responseId');
    if(!$this->YourFunctionCall()) {
        Response::model($surveyId)->updateByPk($responseId,array('submitdate' => null));
        $message = "Your survey canb not be finally submitted".
        $message .= CHtml::link("Retry",array("survey/index", "sid" => $surveyId ));
        \renderMessage\messageHelper::renderAlert($message,'warning');
        App()->end();
    }
Here i use gitlab.com/SondagesPro/coreAndTools/renderMessage

But when i do real system : i use more beforeTwigRender event to allow other plugin to do their job.

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose