In the template:
<form action="<?php echo $page->url() ?>" method="POST">
<textarea name="text"><?php echo $form->old('text') ?></textarea>
<?php echo honeypot_field() ?>
<?php echo csrf_field() ?>
<input type="submit" value="Submit">
</form>
In the controller:
<?php
use Uniform\Form;
return function ($site, $pages, $page)
{
$form = new Form([
'text' => [
'rules' => ['required'],
'message' => 'Please enter something',
],
]);
if (r::is('POST')) {
$form->webhookAction([
'url' => 'your_url',
'json' => true,
'params' => [
'method' => 'POST',
],
]);
}
return compact('form');
};
This should post the submitted text in the Slack channel.
But you probably want to compose the posted message of the content of multiple different form fields. I realized that this can be easily achieved with just a little tweak to the WebhookAction class. I’ve just pushed the tweak to the current master of Uniform. Once you updated your Uniform installation to the current master you can implement a custom action like this:
<?php
namespace Uniform\Actions;
class SlackAction extends WebhookAction
{
protected function transfromData(array $data)
{
return [
'text' => 'Some message from '.$data['email'].':\n'.$data['message'],
];
}
}
Template:
<form action="<?php echo $page->url() ?>" method="POST">
<input name="email" type="email" value="<?php echo $form->old('email') ?>">
<textarea name="message"><?php echo $form->old('message') ?></textarea>
<?php echo csrf_field() ?>
<?php echo honeypot_field() ?>
<input type="submit" value="Submit">
</form>
Controller:
<?php
use Uniform\Form;
return function ($site, $pages, $page)
{
$form = new Form([
'email' => [
'rules' => ['required', 'email'],
'message' => 'Email is required',
],
'message' => [
'rules' => ['required'],
'message' => 'Message is required',
],
]);
if (r::is('POST')) {
$form->slackAction([
'url' => 'your_url',
'json' => true,
'params' => [
'method' => 'POST',
],
]);
}
return compact('form');
};