Send a Form, with data from the view
Created 5 years ago by cyno

Hi! The thing i want to achive is to send a form to a page (between two modules), with entry data from the view. Normally in php/laravel it works easily, but i just cant make it work with pyro. Hope someone can give me some advices. I'm gonna post the codes I currently have.

view.twig:

{{ form('buy_button').setValue('product_slug', product.slug)|raw }}

class ProductBuyButtonFormBuilder extends FormBuilder { protected $ajax = false;

protected $fields = [
    'product_slug' => [
        'type' => 'anomaly.field_type.text',
        'hidden' => true,
        'config' => [
            "default_value" => '0'
        ],
    ],
];

protected $options = [
    'redirect' => 'order'
];

protected $actions = [
    'save' => [
        'enabled' => false
    ]
];

protected $buttons = [
    'buy'
];

}

controller in the other module: class OrdersController extends PublicController {

public function index()
{
    return $this->view->make('hustle.module.orders::checkout');
}

}

and the other modules service provider:

protected $routes = [ 'order' => [ 'as' => 'hustle.module.orders::order.index', 'uses' => 'Hustle\OrdersModule\Http\Controller\OrdersController@index', ],

ryanthompson  —  5 years ago

You want to post TO that route or you want to go to that route afterwards and include like the ID of the entry perhaps?

You can set the redirect option.

protected $options = ['redirect' => 'foo/bar/{entry.id}`]; // Note, not twig
cyno  —  5 years ago

I want to keep the url im posting to without any id. So in this case i want to post to the route i guess. Sorry for the messy code include btw.

cyno  —  5 years ago

I thought the beat way to do this, is to get the posted data in the controller of the route somehow, but i cannot make it work.