我想做的是使用OctoberCMS上的“魔术表单”插件提交表单,并获取从该表单提交的值并将其用于其他功能。
我目前正在OctoberCMS的“代码”部分中进行此操作。我只是不知道如何从事件侦听器外部访问$ formdata的'martin.forms.beforeSaveRecord'。
<?php
use Event as Event;
function onInit()
{
$this['viewBag']->setProperty('redirectUrl', '/order_completed');
Event::listen('studioazura.stripe.setChargePostData', function($self, &$postData, $stripe, $invoice, $address) {
// override amount and description; add key to metadata
$postData['amount'] = 29.99 * 100;
$postData['description'] = 'My Overriden Description';
$postData['metadata']['new_info'] = 'new value';
$postData['metadata']['email'] = 'new value';
});
Event::listen('studioazura.stripe.handleStripeChargeResponse', function($self, $response, $redirect) {
// Send email to admin saying details have been collected
$this->onSend();
});
// Event that returns the form data
Event::listen('martin.forms.beforeSaveRecord', function (&$formdata, $component) {
// $this['viewBag']->setProperty('name', $formdata['name']);
$this['result'] = $formdata['name'];
// How do I access $formdata['name'] and the other fields in my onSend()
});
}
function onSend()
{
$vars = ['name' => 'Joe', 'user' => 'Mary'];
$name = $this['viewBag']->property('name');
$email = post('email');
$message = post('message');
$params = compact('name', $name);
Mail::send('testTemplate', $vars, function($message) {
$message->to('myemail@email.ie', 'Admin Person');
$message->subject('This is a reminder :: ' + $name);
});
}
?>
任何帮助将不胜感激。