Skip to content

Commit

Permalink
closes formr#135
Browse files Browse the repository at this point in the history
  • Loading branch information
timgavin committed Jan 30, 2022
1 parent 2d324d5 commit a6daf20
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Formr

Formr is a PHP micro-framework which installs easily and helps you build, layout and validate forms quickly, painlessly, and without all the complicated, messy overhead.
Formr is a ridiculously fast and easy PHP form builder, with support for Bootstrap and Bulma right out of the box!

Find docs here: [http://formr.github.io](http://formr.github.io)

Expand Down
9 changes: 7 additions & 2 deletions class.formr.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Formr;

/**
* Formr (1.4.1)
* Formr (1.4.2)
*
* a php micro-framework to help you quickly build and validate web forms
*
Expand Down Expand Up @@ -4982,6 +4982,10 @@ public function unset_session()

public function ok()
{
if (isset($_POST['csrf_token']) && !isset($_SESSION['formr']['token'])) {
return false;
}

if (empty($this->errors)) {
return true;
}
Expand Down Expand Up @@ -5138,6 +5142,7 @@ public function recaptcha_passed()
'response' => $_POST['formrToken'],
'remoteip' => $_SERVER['REMOTE_ADDR']
],
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true
]);
$response = curl_exec($ch);
Expand All @@ -5149,7 +5154,7 @@ public function recaptcha_passed()
# convert the json encoded string to a php variable
$result = json_decode($response, true);

if ($result['success'] == true && $result['score'] >= $this->recaptcha_score) {
if (!empty($result) && ($result['success'] == true) && ($result['score'] >= $this->recaptcha_score)) {
return true;
}

Expand Down
34 changes: 23 additions & 11 deletions lib/wrappers/bulma.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public function bulma($element = '', $data = '')
$return .= '<div class="field">' . $this->nl;
}

$return .= ' <label class="'.$data['type'].'">' . $this->nl;
$return .= $element . $this->nl;
$return .= $data['label'] . $this->nl;
$return .= ' </label>' . $this->nl;
$return .= '<label class="' . $data['type'] . '">' . $this->nl;
$return .= $element . $this->nl;
$return .= $data['label'] . $this->nl;
$return .= '</label>' . $this->nl;

# show error message
if ($this->formr->submitted() && $this->formr->in_errors($data['name']) && $this->formr->inline_errors) {
$return .= '<p class="help is-danger">'.$this->formr->errors[$data['name']].'</p>';
$return .= '<p class="help is-danger">' . $this->formr->errors[$data['name']] . '</p>';
}

# close the wrapper
Expand All @@ -82,7 +82,13 @@ public function bulma($element = '', $data = '')
$return .= '<div class="field">' . $this->nl;
}

$return .= $data['label'] ? '' : '<label class="label">' . $data['label'] . '</label>' . $this->nl;
if ($this->formr->is_not_empty($data['label'])) {
$return .= '<label class="label" for="' . $this->formr->make_id($data) . '">' . $this->nl;
$return .= "\t" . $data['label'];
$return .= $this->formr->insert_required_indicator($data) . $this->nl;
$return .= '</label>' . $this->nl;
}

$return .= ' <div class="file">' . $this->nl;
$return .= ' <label class="file-label">' . $this->nl;
$return .= $element . $this->nl;
Expand All @@ -99,7 +105,7 @@ public function bulma($element = '', $data = '')

# show error message
if ($this->formr->submitted() && $this->formr->in_errors($data['name']) && $this->formr->inline_errors) {
$return .= '<p class="help is-danger">'.$this->formr->errors[$data['name']].'</p>';
$return .= '<p class="help is-danger">' . $this->formr->errors[$data['name']] . '</p>';
}

# close the wrapper
Expand All @@ -119,7 +125,13 @@ public function bulma($element = '', $data = '')
$return .= '<div class="field">' . $this->nl;
}

$return .= $data['label'] ? '' : '<label class="label">' . $data['label'] . '</label>' . $this->nl;
if ($this->formr->is_not_empty($data['label'])) {
$return .= '<label class="label" for="' . $this->formr->make_id($data) . '">' . $this->nl;
$return .= "\t" . $data['label'];
$return .= $this->formr->insert_required_indicator($data) . $this->nl;
$return .= '</label>' . $this->nl;
}

$return .= ' <div class="control">' . $this->nl;
$return .= ' <div class="select">' . $this->nl;
$return .= $element . $this->nl;
Expand All @@ -128,7 +140,7 @@ public function bulma($element = '', $data = '')

# show error message
if ($this->formr->submitted() && $this->formr->in_errors($data['name']) && $this->formr->inline_errors) {
$return .= '<p class="help is-danger">'.$this->formr->errors[$data['name']].'</p>';
$return .= '<p class="help is-danger">' . $this->formr->errors[$data['name']] . '</p>';
}

# close the wrapper
Expand All @@ -149,7 +161,7 @@ public function bulma($element = '', $data = '')

if ($this->formr->is_not_empty($data['label'])) {
$return .= '<label class="label" for="' . $this->formr->make_id($data) . '">' . $this->nl;
$return .= "\t".$data['label'];
$return .= "\t" . $data['label'];
$return .= $this->formr->insert_required_indicator($data) . $this->nl;
$return .= '</label>' . $this->nl;
}
Expand Down Expand Up @@ -185,7 +197,7 @@ public function bulma($element = '', $data = '')
}
} else {
if ($this->formr->submitted() && $this->formr->in_errors($data['name']) && $this->formr->inline_errors) {
$return .= '<p class="help is-danger">'.$this->formr->errors[$data['name']].'</p>';
$return .= '<p class="help is-danger">' . $this->formr->errors[$data['name']] . '</p>';
}
}

Expand Down

0 comments on commit a6daf20

Please sign in to comment.