| @@ -129,9 +129,13 @@ | ||
| 129 | 129 | /** |
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | 132 | public function get_markup() { |
| 133 | - return apply_filters( 'hf_form_markup', $this->markup ); | |
| 133 | + /** | |
| 134 | + * @param string $markup | |
| 135 | + * @param Form $form | |
| 136 | + */ | |
| 137 | + return apply_filters( 'hf_form_markup', $this->markup, $this ); | |
| 134 | 138 | } |
| 135 | 139 | |
| 136 | 140 | /** |
| 137 | 141 | * @return array |
| @@ -174,11 +178,15 @@ | ||
| 174 | 178 | } |
| 175 | 179 | |
| 176 | 180 | /** |
| 177 | 181 | * @return int The number of named fields in the form |
| 182 | + * | |
| 183 | + * Note: this includes all default fields and an additional field for the "was-required" element we include in every request. | |
| 178 | 184 | */ |
| 179 | 185 | public function get_field_count() { |
| 180 | - $count = substr_count( strtolower( $this->get_html() ), ' name=' ); | |
| 186 | + $pattern = '/\bname\s*=\s*["\']/i'; | |
| 187 | + preg_match_all( $pattern, $this->get_html(), $matches ); | |
| 188 | + $count = ! empty( $matches ) ? count( $matches[0] ) : 0; | |
| 181 | 189 | $count++; // Add one for 'was-required' |
| 182 | 190 | return $count; |
| 183 | 191 | } |
| 184 | 192 | } |