This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Shapeless
Shapeless

Hello,

I am trying to save to the database when clicking submit button on a form. I am trying to follow the tutorial called "Mastering Components" on the resources page. I have a form that has a data-request="{{ SELF }}::onAddItem" and in my components I have the function

    public function onAddItem()
    {
        $yearsubmit = post('year');
        $date = new Shapeless\Data\Models\EtradeModel;
        $date->year = $yearsubmit;
        $date->save();

        $this->page['dates'] = EtradeModel::lists('year');
    }

Last updated

daftspunky
daftspunky

I can see a few issues with PHP namespaces there, perhaps you should read up on it.

Are you getting any error messages?

Shapeless
Shapeless

I am not getting any errors... No camel case Models?

Shapeless
Shapeless

I'm not understanding...what are the namespace issues? I was able to follow the tutorial up until this part.

Shapeless
Shapeless

i figured it out. It was something stupid :(

Great work on those tutorials by the way :) they helped a lot

andy.tan26244485
andy.tan26244485

Hi There, I'm also having similar problems as Shapeless. I've tried to recreate to To Do Plugin and interact with the database, but it doesn't seem to be adding anything to the database or reaching my onAddItem code. Do you know if this is a common problem or know how to turn on debugging to see any error logs

Here's my code for my default.htm to show the form to save To Do Items

<form data-request="{{SELF}}::onAddItem()" data-request-success="$('#inputItem').val('')" data-request-update="{{SELF}}::tasks': '#result'"

And the onAddItem code in Todo.php looks like

`public function onAddItem()
{
    $taskName = post('task');
    $task = new task;
    $task->title = $taskName;
    $task->save();

    $this->page['tasks'] = Task::lists('title');
}`

P.S. I'm using this to import the Task class use Atan\Demo\Models\Task;

It works to retrieve tasks from the database, but can't figure out how to save data

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.