2929use Solspace \Freeform \Library \Logging \LoggerInterface ;
3030use Solspace \Freeform \Library \Session \FormValueContext ;
3131use Solspace \Freeform \Library \Translations \TranslatorInterface ;
32- use Solspace \Freeform \Models \FieldModel ;
3332
3433class Form implements \JsonSerializable, \Iterator, \ArrayAccess
3534{
@@ -63,6 +62,9 @@ class Form implements \JsonSerializable, \Iterator, \ArrayAccess
6362 /** @var bool */
6463 private $ storeData ;
6564
65+ /** @var bool */
66+ private $ ipCollectingEnabled ;
67+
6668 /** @var int */
6769 private $ defaultStatus ;
6870
@@ -123,16 +125,16 @@ class Form implements \JsonSerializable, \Iterator, \ArrayAccess
123125 /**
124126 * Form constructor.
125127 *
126- * @param Properties $properties
127- * @param FormAttributes $formAttributes
128- * @param array $layoutData
129- * @param FormHandlerInterface $formHandler
130- * @param FieldHandlerInterface $fieldHandler
131- * @param SubmissionHandlerInterface $submissionHandler
132- * @param SpamSubmissionHandlerInterface $spamSubmissionHandler
133- * @param FileUploadHandlerInterface $fileUploadHandler
134- * @param TranslatorInterface $translator
135- * @param LoggerInterface $logger
128+ * @param Properties $properties
129+ * @param FormAttributes $formAttributes
130+ * @param array $layoutData
131+ * @param FormHandlerInterface $formHandler
132+ * @param FieldHandlerInterface $fieldHandler
133+ * @param SubmissionHandlerInterface $submissionHandler
134+ * @param SpamSubmissionHandlerInterface $spamSubmissionHandler
135+ * @param FileUploadHandlerInterface $fileUploadHandler
136+ * @param TranslatorInterface $translator
137+ * @param LoggerInterface $logger
136138 *
137139 * @throws FreeformException
138140 * @throws \Solspace\Freeform\Library\Exceptions\Composer\ComposerException
@@ -149,18 +151,18 @@ public function __construct(
149151 TranslatorInterface $ translator ,
150152 LoggerInterface $ logger
151153 ) {
152- $ this ->properties = $ properties ;
153- $ this ->formHandler = $ formHandler ;
154- $ this ->fieldHandler = $ fieldHandler ;
155- $ this ->submissionHandler = $ submissionHandler ;
156- $ this ->spamSubmissionHandler = $ spamSubmissionHandler ;
157- $ this ->fileUploadHandler = $ fileUploadHandler ;
158- $ this ->translator = $ translator ;
159- $ this ->logger = $ logger ;
160- $ this ->storeData = true ;
161- $ this ->customAttributes = new CustomFormAttributes () ;
162- $ this ->errors = [] ;
163- $ this ->markedAsSpam = false ;
154+ $ this ->properties = $ properties ;
155+ $ this ->formHandler = $ formHandler ;
156+ $ this ->fieldHandler = $ fieldHandler ;
157+ $ this ->submissionHandler = $ submissionHandler ;
158+ $ this ->spamSubmissionHandler = $ spamSubmissionHandler ;
159+ $ this ->fileUploadHandler = $ fileUploadHandler ;
160+ $ this ->translator = $ translator ;
161+ $ this ->logger = $ logger ;
162+ $ this ->storeData = true ;
163+ $ this ->ipCollectingEnabled = true ;
164+ $ this ->customAttributes = new CustomFormAttributes () ;
165+ $ this ->errors = [] ;
164166
165167 $ this ->layout = new Layout (
166168 $ this ,
@@ -322,6 +324,14 @@ public function getDefaultStatus(): int
322324 return $ this ->defaultStatus ;
323325 }
324326
327+ /**
328+ * @return int
329+ */
330+ public function isIpCollectingEnabled (): bool
331+ {
332+ return (bool ) $ this ->ipCollectingEnabled ;
333+ }
334+
325335 /**
326336 * @return bool
327337 */
@@ -513,7 +523,7 @@ public function submit()
513523 if ($ this ->storeData && $ this ->hasOptInPermission ()) {
514524 $ submission = $ this ->saveStoredStateToDatabase ();
515525 } else {
516- $ submission = $ this ->getSubmissionHandler ()->createSubmissionFromForm ($ this );
526+ $ submission = $ this ->getSubmissionHandler ()->createSubmissionFromForm ($ this );
517527 $ this ->formSaved = true ;
518528 }
519529
@@ -578,7 +588,7 @@ public function getMailingListOptedInFields(): array
578588 {
579589 $ fields = [];
580590 foreach ($ this ->getLayout ()->getMailingListFields () as $ field ) {
581- $ field = $ this ->getLayout ()->getFieldByHandle ($ field ->getHandle ());
591+ $ field = $ this ->getLayout ()->getFieldByHandle ($ field ->getHandle ());
582592 $ fieldValue = $ field ->getValue ();
583593 if ($ fieldValue && $ field ->getEmailFieldHash () && $ field ->getResourceId ()) {
584594 $ fields [] = $ field ;
@@ -588,7 +598,7 @@ public function getMailingListOptedInFields(): array
588598 return $ fields ;
589599 }
590600
591- /**
601+ /**
592602 * Render a predefined template
593603 *
594604 * @param array $customFormAttributes
@@ -797,6 +807,7 @@ private function buildFromData(FormProperties $formProperties)
797807 $ this ->description = $ formProperties ->getDescription ();
798808 $ this ->returnUrl = $ formProperties ->getReturnUrl ();
799809 $ this ->storeData = $ formProperties ->isStoreData ();
810+ $ this ->ipCollectingEnabled = $ formProperties ->isIpCollectingEnabled ();
800811 $ this ->defaultStatus = $ formProperties ->getDefaultStatus ();
801812 $ this ->formTemplate = $ formProperties ->getFormTemplate ();
802813 $ this ->optInDataStorageTargetHash = $ formProperties ->getOptInDataStorageTargetHash ();
@@ -876,7 +887,8 @@ private function saveStoredStateToDatabase()
876887 *
877888 * @throws \Solspace\Freeform\Library\Exceptions\Composer\ComposerException
878889 */
879- public function getAdminNotificationProperties () {
890+ public function getAdminNotificationProperties ()
891+ {
880892 return $ this ->properties ->getAdminNotificationProperties ();
881893 }
882894
@@ -885,7 +897,8 @@ public function getAdminNotificationProperties() {
885897 *
886898 * @return DynamicNotificationAttributes|null
887899 */
888- public function getDynamicNotificationData () {
900+ public function getDynamicNotificationData ()
901+ {
889902 return $ this ->getFormValueContext ()->getDynamicNotificationData ();
890903 }
891904
@@ -1024,7 +1037,8 @@ public function offsetUnset($offset)
10241037 throw new FreeformException ('Form ArrayAccess does not allow unsetting values ' );
10251038 }
10261039
1027- private function isLastPage () {
1040+ private function isLastPage ()
1041+ {
10281042 return $ this ->getFormValueContext ()->getCurrentPageIndex () === (\count ($ this ->getPages ()) - 1 );
10291043 }
10301044}
0 commit comments