Ad

October Cms, Plugin, Forms That Accepts Input From User In Front-end Of The Web

- 1 answer

i am trying to create plugin for october cms and i am curious, what is the best way to create forms that is able to appcept input from user in fronend and put it all to the Data Base?

Ad

Answer

First of all you should create component. You can add your form to default.htm:

<form data-request="onTest" data-request-update="calcresult: '#result'">
    <input type="text" name="value1">
    <input type="text" name="value2">
    <input type="submit" value="Calculate">
</form>
<div id="result"></div>

Then you should add you component to CMS Page. In component's php file you can create new function:

public function onTest()
{
    $value1 = post('value1');
    $value2 = post('value2');
    // insert you values to your model
    $flight = new Flight;
    $flight->value1 = $value1;
    $flight->value2= $value2;
    $flight->save();
    // or directly to database
    Db::table('users')->insert(
      ['value1' => $value1, 'value2' => $value2]
    );
    return TRUE;
}

You can find more about Models and Queries and Ajax in official documentation.

Ad
source: stackoverflow.com
Ad