CMS  Version 3.9
RequiredQuestionnaireMessageValidator Class Reference

If a survey allows anonymous responses, then email message is only required if the user enters a recipient, additional recipient, or cc recipient. More...

Inherits RequiredValidator.

Public Member Functions

 __construct ($form, $field, $title="", $message="")
 
 writeClient ()
 
 validate ()
 

Public Attributes

 $conditionalFields = array()
 

Detailed Description

If a survey allows anonymous responses, then email message is only required if the user enters a recipient, additional recipient, or cc recipient.

This validator is only used in the case of survey allow_anonymous_responses == true.

Author
janice

Definition at line 270 of file validation.inc.

Constructor & Destructor Documentation

◆ __construct()

RequiredQuestionnaireMessageValidator::__construct (   $form,
  $field,
  $title = "",
  $message = "" 
)

Definition at line 274 of file validation.inc.

275  {
276  $this->AbstractValidator($field, $title);
277  $this->conditionalFields[] = "recipients";
278 
279  if($form->data->hasField("additional_recipients"))
280  {
281  $this->conditionalFields[] = "additional_recipients";
282  }
283 
284  if($form->data->hasField("cc_recipients"))
285  {
286  $this->conditionalFields[] = "cc_recipients";
287  }
288  }
$form

Member Function Documentation

◆ validate()

RequiredQuestionnaireMessageValidator::validate ( )

Definition at line 316 of file validation.inc.

317  {
318  global $_POST;
319 
320  if ($this->readOnly) return "";
321 
322  $empty = true;
323  if(count($this->conditionalFields) > 0)
324  {
325  foreach($this->conditionalFields as $field)
326  {
327  if(isset($_POST[$this->field]) && $_POST[$this->field] !== $this->empty)
328  {
329  $emtpy = false;
330  }
331  }
332  }
333 
334  if ((!isset($_POST[$this->field]) || $_POST[$this->field] === $this->empty)
335  && (!count($this->conditionalFields) || !$empty))
336  {
337  return "{$this->title} is a required field.";
338  }
339  else
340  {
341  return "";
342  }
343  }
$_POST["owner_id"]
Definition: blog_form.inc:54
$openData field

◆ writeClient()

RequiredQuestionnaireMessageValidator::writeClient ( )

Definition at line 290 of file validation.inc.

291  {
292  if ($this->readOnly) return "";
293 
294  if(count($this->conditionalFields) > 0)
295  {
296  $conditions = array();
297  foreach($this->conditionalFields as $field)
298  {
299  $conditions[] = "form[\"{$field}\"].value != \"{$this->empty}\"";
300  }
301  $conditions = "(" . implode(" || ", $conditions) . ") && ";
302  }
303 
304  $script = <<<ENDSCRIPT
305 
306  if ({$conditions}form["{$this->field}"].value == "{$this->empty}")
307  {
308  alert("{$this->title} is a required field. Please supply a value.");
309  return false;
310  }
311 ENDSCRIPT;
312 
313  return $script;
314  }

Member Data Documentation

◆ $conditionalFields

RequiredQuestionnaireMessageValidator::$conditionalFields = array()

Definition at line 272 of file validation.inc.


The documentation for this class was generated from the following file: