Form action getting url instead of route and addData to view

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
lucadambros
Posts: 44
Joined: 24 Jun 2019, 14:46

Form action getting url instead of route and addData to view

Post by lucadambros » 07 Aug 2019, 10:09

Hi,
I tried to create a form inside an existing template. I have the same form inside the
welcome.blade.php
template so I'm sure that the form works. I added the route in right page and everything else.

Here is the example code of the form:

Code: Select all

<form method="POST" action="{{ route('changecar') }}">
        <select>
		<option value="3">Volvo</option>
		<option value="1">Saab</option>
		<option value="2">Mercedes</option>
		<option value="4">Audi</option>
	</select>
	<button type="submit">test</button>			
</form>
In the
client/html/templates/catalog/detail/body-standard.php
I added the same form but it's not working.

The form creates a url like this

Code: Select all

http://127.0.0.1:8000/shop/Demo_bundle_article/%7B%7B%20route('changecar')%20%7D%7D 
Why is the form acting like this? How can I solve this problem?

Is there a way to add a data to the view every time I call this form?

Thanks

lucadambros
Posts: 44
Joined: 24 Jun 2019, 14:46

Re: Form action getting url instead of route and addData to view

Post by lucadambros » 07 Aug 2019, 12:06

I found the solution so I changed the form like this:

Code: Select all

<form method="POST" action="<?= route('changecar'); ?>">
	<?= $this->csrf()->formfield(); ?>
	<select>
		<option value="3">Volvo</option>
		<option value="1">Saab</option>
		<option value="2">Mercedes</option>
		<option value="4">Audi</option>
	</select>
	<button type="submit">test</button>
</form>
This code works but I can't understand one thing: I defined a controller inside my ext but I can't define a route for that controller. What I have to do?

I get

Code: Select all

message: "Target [Aimeos\MShop\Context\Item\Iface] is not instantiable while building [Aimeos\Client\Html\Catalog\Detail\MyController]."

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Form action getting url instead of route and addData to view

Post by aimeos » 08 Aug 2019, 07:05

The HTML clients are no Laravel controllers, only PHP classes. You can use them in your own Laravel controllers. Please have a look at the existing ones.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

lucadambros
Posts: 44
Joined: 24 Jun 2019, 14:46

Re: Form action getting url instead of route and addData to view

Post by lucadambros » 20 Aug 2019, 11:48

Is there a way to modify the view after submitting the form from the controller?

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Form action getting url instead of route and addData to view

Post by aimeos » 20 Aug 2019, 14:36

The HTML client classes have a process() method that is called when data is sent through forms (you can set view data too) and the addData() method to add more data to the view (maybe based on the already set data).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

lucadambros
Posts: 44
Joined: 24 Jun 2019, 14:46

Re: Form action getting url instead of route and addData to view

Post by lucadambros » 20 Aug 2019, 15:13

How can I understand if I'm sending data through form inside the "process" function?

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Form action getting url instead of route and addData to view

Post by aimeos » 21 Aug 2019, 07:20

Use

Code: Select all

$this->getView()->param( <input field name> [, <default value>] )
to check if the form has been posted
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

lucadambros
Posts: 44
Joined: 24 Jun 2019, 14:46

Re: Form action getting url instead of route and addData to view

Post by lucadambros » 21 Aug 2019, 07:59

Sorry I can't understand. I will try to explain better what I want.

I have a form. Every option of this form must execute a php function (that can be inside the process/addData functions) and display the new data without refreshing the page.

I must NOT use JQuery. Can you show me an example form and function please?

User avatar
aimeos
Administrator
Posts: 7858
Joined: 01 Jan 1970, 00:00

Re: Form action getting url instead of route and addData to view

Post by aimeos » 22 Aug 2019, 07:59

Can you post how your form looks like?

You have to use an XHR/AJAX request if you want to refresh the content without page reload. If it's not jQuery you have to use another JS library or try plain JS.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

lucadambros
Posts: 44
Joined: 24 Jun 2019, 14:46

Re: Form action getting url instead of route and addData to view

Post by lucadambros » 22 Aug 2019, 08:04

I found another way to do all this:
- I have a form
- onchange this form will make an ajax call
- the ajax call is a laravel function
- jquery will send the new data without refreshing the page
- the laravel function will store the data I need

Post Reply