Forums

Creating survey with each Q and A pair saved to a DB record. Is it possible to not save records for unanaswered questions?

farscape 08 Feb, 2018
Hi!

I have a questionnaire designed to save each question number (q1, q2, etc) and answer pair in separate records. Currently, I'm using a Save Data action inside of a Loop Event. As designed, it saves a record even for questions that are not answered. Is there a way to NOT save a record for unanswered questions?

Thanks!
GreyHead 09 Feb, 2018
Hi farscape,

You can use a Custom Code action before the Loop action to loop through the data array and unset any entries with no answer.

Bob
farscape 13 Feb, 2018
Bob,

Thanks. I'm an amateur regarding PHP, but I've searched for relevant code. When I search simply for removing blank values from an array, the results talk more about array_filter than unset. I've tried both with no success. I think my issue is how to reference the array in the PHP.

The bottom of page 34 of the Chronoforms v6 manual shows how to reference fields, but not entire arrays. So I've tried variations of what page 34 says. The array is called "service", as shown below. If I try to do something like $array = this->service, it doesn't work. Additional searching uncovered a post from another forum that says that the "dash arrow" is for an object, and that an array is not an object.

Help from anyone appreciated.
   [service] => Array
(
[1] => Array
(
[question] => q1
[answer] => 1
)

[2] => Array
(
[question] => q2
[answer] =>
)

)
This topic is locked and no more replies can be posted.