October: Can't attach image in `create` modal window

Created on 30 Apr 2017  路  3Comments  路  Source: octobercms/october

Reproduce steps

Install this fork of plugin
https://github.com/PopcornPHP/currency-plugin

Go to /backend/responsiv/currency/currencies , and create new currency. There, in the bottom of modal window, there is field named 'IMAGE'. This image will be uploaded, but not attached. If click on uploaded thumbnail - you can see error:
"A widget with class name 'formRelImage' has not been bound to the controller" on line 523 of \modules\backend\classes\Controller.php

October build

418

If this is not an error - then how do I properly attach an image in modal windows?

Question third party

Most helpful comment

Please observe this video series, it is somewhat a right of passage for this level of issue.

https://youtu.be/llo6xyKx3i0?list=PLfQvk5RK_e-Zim57m_CptCXYlgFT7P_sv

  • How MVC works in October CMS
  • Rendering Lists and Forms by hand
  • Implementing a nested relationship (this one has the answer)

Essentially your file upload widget is not bound to the controller because the form exists only to render in a modal. You should pass through a post variable to trigger the binding in the constructor.

public function __construct()
{
    // ....

    if (post('form_mode')) {
        $this->asExtension('FormController')->create();
    }
}

The above code simply creates an empty model instance for you (create mode) and boots up the form and its widgets--binding them to the controller, making them available.

Then adding <input type="hidden" name"form_mode" value="1" /> to the create modal markup.

GLHF!

All 3 comments

Please observe this video series, it is somewhat a right of passage for this level of issue.

https://youtu.be/llo6xyKx3i0?list=PLfQvk5RK_e-Zim57m_CptCXYlgFT7P_sv

  • How MVC works in October CMS
  • Rendering Lists and Forms by hand
  • Implementing a nested relationship (this one has the answer)

Essentially your file upload widget is not bound to the controller because the form exists only to render in a modal. You should pass through a post variable to trigger the binding in the constructor.

public function __construct()
{
    // ....

    if (post('form_mode')) {
        $this->asExtension('FormController')->create();
    }
}

The above code simply creates an empty model instance for you (create mode) and boots up the form and its widgets--binding them to the controller, making them available.

Then adding <input type="hidden" name"form_mode" value="1" /> to the create modal markup.

GLHF!

Thank you very match! Everything is working

Thanks @daftspunk

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dunets picture dunets  路  3Comments

mittultechnobrave picture mittultechnobrave  路  3Comments

Flynsarmy picture Flynsarmy  路  3Comments

pavelmgn picture pavelmgn  路  3Comments

lukaszbanas-extremecoding picture lukaszbanas-extremecoding  路  3Comments