Unanswered Or Irrelevant Question Management

indieben 14 Mar, 2019
A few questions please:

1) Is it possible to avoid having unanswered questions (whether they were disabled and hidden through the form conditions or not) displaying within Custom Email Setups? If so, how do you go about that please?
2) Is it possible to create an alternative phrase for unanswered questions (for example: "The Client Does not Require This Service" and have a slightly different version for the Client: "You Have Stated That You Do Not Require This Service"

3) In a checkbox situation, is it possible to hav/calle the value displayed to the user on the website sent in the Email instead of the internal value. y=yes etc.

Thanks ever so much.
healyhatman 14 Mar, 2019
1) You can craft the email yourself manually instead of relying on auto added fields. You can do this in a custom code block set to "return as var" where you use HTML and PHP to echo / display whatever you want, then just use {var:custom_code_block_name} in your email body.

2) Again you can put whatever you want.

3) No. Unless you manually do it as described above.
indieben 14 Mar, 2019
Thanks for this, are there any up to date Chronoforms instructions out there? I know the question has been asked once or twice before but as Chronoforms is constantly evolving, things may have come a darn site easier than it looked before...

Thanks.
healyhatman 14 Mar, 2019
Nope he's been too busy fixing bugs and adding new features to be able to add new stuff to a manual. What are you after exactly?
indieben 14 Mar, 2019
Where to start with achieving the above essentially, i'd hoped that there were some guides (not necessarily the official manual) that are trusted amongst regulars... I have no idea where to start with the above!

Thanks.
healyhatman 14 Mar, 2019
1 Likes
In a Custom Code block set to return var
<?php
echo "This field will show Not Answered if it's not there: " . ($this->data("fieldname") ?: "Not answered");
?>
<br>
More Text Goes here!
<?php
if(!empty($this->data("myotherfieldname"))) {
echo "This field exists so I will show it otherwise I wouldn't show anything: " . $this->data("myotherfieldname");
}
?>
indieben 14 Mar, 2019
Bless you healyhatman, I shall play with this. Thanks a hell of a lot. May come back to you - please have patience with me if I fudge it up!
indieben 15 Mar, 2019
Hi Healyhatman,

A) So - How do the two work different in practice (i.e. in straight English please)?:

1)
echo "This field will show Not Answered if it's not there: ...

2)
if(!empty($this->data("myotherfieldname"))) { ...
3. I notice in the case of example 2 - it goes on:

 echo "This field exists so I will show it otherwise I wouldn't show anything: " . $this->data("myotherfieldname");

So, in the second example, it takes two fields, what is the difference please? I presume the field names are the green ones instead of the black ones?

C) I presume the custom code block would go at the top of the form or somewhere within the design view of the form?

D) The "block name", I'm not familiar with the blocks bit, how do I get that please?

C) Do I call all the fields in the same way as normal (within the Email Section) but the PHP overrides it - essentially an expected behaviour question?

Sorry if I appear dumb, i'm sure this will help a fair few people🙂

Thanks!
healyhatman 15 Mar, 2019
A) 1) Shows a label and the either the value of the field OR if it wasn't answered a message saying "Not Answered"
2) If the question wasn't answered, doesn't show anything. 2 is the part that checks if it was Not Empty, 3 is the part that displays the message.

C) It goes before your email action.
D) "Custom code block name" is the name of your custom code block. Unanswered Or Irrelevant Question Management image 1
C (again for some reason, I assume you mean E)) No like I said you put {var:custom_code_block_name} in the email body. If your code block was named like the one in the picture it would be {var:custom_code3}
indieben 15 Mar, 2019
Thanks for this.

So in version 1 at https://pastebin.com/0zBrKyRh I realised that the:
This field will show Not Answered if it's not there
will print out - fine - no surprise that that happens.

So I developed version 2 to get rid of that:

https://pastebin.com/sT3ww9Jw

But both forms display to the user on the screen - they shouldn't - I'll use a standard display message for that and neither actually carry out the substitution in the Email generated if a field value is left blank.

Sorry to be rather slow here I have asked around and drawn a blank.

Thanks,

indieben.
healyhatman 15 Mar, 2019
Did you tick the return as var button?
indieben 16 Mar, 2019
I hadn't but I tried it with that and it still displayed on the screen and does not output the substituted message for the field in the Email when the particular question isn't completed - it does appear to omit some fields if they are not completed though but, not, for example, "Is the Trainee Based in the Uk" on this form https://www.samspencerit.co.uk/index.php/quotation-request

Thanks🙂
healyhatman 16 Mar, 2019
If you ticked the box there's no reason the code you've put in should be displayed on the screen unless you're telling it to.
indieben 17 Mar, 2019
Sure, i must have got something wrong unless Gantry Is doing something odd!! I’ll run off a copy of Joomla without Gantry and see if that changes anything - i’ll pastebin the current code I’m using too ( an adaptation of yours) if you’d be kind enough to double check that.

Thanks ever so much!
indieben 21 Mar, 2019
OK, ruled out Gantry and moved the form over to a clean Joomla install. No difference. The current code is available at https://pastebin.com/WbVyjjqR - the PHP channel on IRC say that my code is not valid. I can't see how it is different from yours since it was outputting the message at the start: "This field will show Not Answered if it's not there:
"This field will show Not Answered if it's not there:
Please would you point out if I have got the code wrong.

Thanks.
healyhatman 21 Mar, 2019
You're not actually DOING anything with the data buddy.
<?php
($this->data("direct_request_check") ?: "Not answered");
That doesn't DO anything. You told it to get the value but haven't told it to assign it, or print it, or anything. You need to echo it out. Plus you have to put the label first.


You should be doing something like the following. I assume the direct_request_check is a checkbox that has a value of 1 and a ghost value of 0.
Direct Request Check: <?php echo $this->data("direct_request_check") ? "Checked" : "Not checked"; ?>
<br>
Enquirer First Name: <?php echo $this->data("enquirer_first_name") ?: "Not answered"; ?>
<br>
etcetcetc
indieben 21 Mar, 2019
Aha, bit different than i'd originally thought depending on the field type! It's actually a radio button so how would that work compared to the checked/not checked above please?

Thanks - hope you have had a good week so far!
healyhatman 21 Mar, 2019
It's just an example. If it's a radio then it depends on the value being sent by the field. You might just have to consider having someone like me do it for you for a fee. Here's another example, assuming a radio group with 3 possible values
​[pre]Favourite Fruit:
<?php switch($this->data("fav_fruit")) {
case 1: echo "apple"; break;
case 2: echo "banana"; break;
case 3: echo "tomato"; break;[br] }[br]?>[br]<br>[/pre]
Or if you want to use a switch action (NOT switch event)[br]data source: {data:fav_fruit}[br]name: fav_fruit_switch[br]Return as var: checked[br]Content:
1:apple
2:banana
3:tomato
And then in your custom code email body building block
Favourite Fruit: {var:fav_fruit_switch}
indieben 21 Mar, 2019
so the first example is a switch event, the second is a switch action? Would these go ahead of the Email action, by this point I will have the Email custom code and the code above, is there any specific order required for the two blocks ahead of Email? Also could this not be done a lot more simply by using isset and a check on that?

Thanks.
healyhatman 21 Mar, 2019
No, the first example (of favourite fruit) is a PHP switch statement. I haven't recommended a switch event for anything you're trying to do.

And if they were AFTER the email action, then the email will have already been sent when it's time to run the code. So it goes before it. And no, isset is for a VARIABLE, whereas $this->data is a function. isset($this->data("fieldname")) will (most likely) always be true. If you want, you can use if empty. But it won't be easier, because the first example (for Direct Request Check) becomes like this
​[pre]Direct Request Check:
<?php if(empty($this->data("direct_request_check"))) {[br] echo "Not checked";[br] }[br] else {[br] echo "Checked";[br] }[br]?><br>[br]Enquirer First Name:[br]<?php if(empty($this->data("enquirer_first_name"))) {[br] echo "Not answered";[br] }[br] else {[br] echo $this->data("enquirer_first_name");[br] } [br]?><br>[/pre]
[br] And I think that surely we can both agree that's not in any way "easier" than using the ternary operators I used in the first (Direct Request Check) example.
indieben 21 Mar, 2019
For the two examples in favourite fruit radio buttons, how would you have, effectively, "else - this field was not completed" and how would that sit with the code above?

Thanks ever so much,

indieben.
indieben 21 Mar, 2019
Thanks for this and yes I see your point.

Ok, I have put together a script based on what you said but i've used the code for the radio for the checkboxes as you had not included anywhere for an alternative message. It's set to return as var, it's set as custom code (above Email) and the whole script is placed within the one box in a clean version of Joomla (without complications).

Unfortunately the script is still outputting to the screen and not taking effect in the Email.

Many thanks.

indieben.


https://pastebin.com/mMqEwEVK
healyhatman 21 Mar, 2019
If it's set to return as var and it's outputting still then straight up you've done something wrong. Send me access details and I'll look.
indieben 08 Apr, 2019
HI I dropped you an email with the form attached some time back, did you get it? Thanks.
This topic is locked and no more replies can be posted.