Skip to content

Commit

Permalink
Merge branch 'master' into experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaladapt committed Aug 10, 2020
2 parents adab76d + 0487545 commit 81b8181
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# magento-vigilant-form-kit
Magento Module for VigilantForm.

**Warning: Alpha release, still working out all the details.**

## So what is this?
I'm working on a Magento Module to make it easy to push form submissions into an instance of VigilantForm.
A Magento Module to make it easy to push form submissions into an instance of VigilantForm.

## So how is it used?
First you add the library:
Expand All @@ -29,14 +27,49 @@ website and form_title will default to hostname and "submit" respectively.
}
```

**TODO: Once I have finished implementing everything, I need to revisit documentation to ensure it is complete and accurate.**
Then use dependency injection to get the `\VigilantForm\MagentoKit\VigilantFormMagentoKit` class into whatever block or controller which has the form you want to validate.
```php
// SomeBlock.php
<?php

Finally, redeploy your Magento website to detect the new module and recompile the dependency injection.
namespace SomeVendor\SomeModule\Block;

class SomeBlock extends \Magento\Framework\View\Element\Template
{
protected $vfmk;

public function __construct(\VigilantForm\MagentoKit\VigilantFormMagentoKit $vfmk)
{
$this->vfmk = $vfmk;
}

public function getVFMK()
{
return $this->vfmk;
}
}
```

Within the form template you call generateHoneypot() within the html form:
```php
// some_block.phtml
<?php /** @var \SomeVendor\SomeModule\Block\SomeBlock $block */ ?>
<form>
<?php echo $block->getVFMK()->generateHoneypot(); ?>
</form>
```

I will probably refactor the Bootstrap class to simplify the process of generating the honeypot and submitting the form, but for now:
When handling form submissions, you also dependency inject the VigilantFormMagentoKit
class, which has the `submitForm()` function. If the submission fails to be stored,
it will throw an UnexpectedValueException.
```php
$params = $this->getRequest()->getPost();
try {
$this->vfmk->submitForm($params);
} catch (\UnexpectedValueException $exception) {
/* do something, in the event failed to store form submission */
}

Now you can add the honeypot field into any forms you want to validate.
Where you echo the `generateHoneypot()` from the VigilantFormKit into your form template.
```

When handling form submissions, you can dependency inject the Bootstrap
class, which has a `create()` function, to tap into, so you can get the VigilantFormKit and call `submitForm()`.
Finally, redeploy your Magento website to detect the new module and recompile the dependency injection.

0 comments on commit 81b8181

Please sign in to comment.