Post by prototype0104 » Wed Sep 25, 2019 6:13 pm

Hi! I'm using opencart 3.0.3.2. I'm newbie, how to send variables to controller from twig form?
Example:

Code: Select all

<input type="text" name="originalcode" placeholder="Original code" />
<button type="button" id="button-copyams" formaction="{{ amscopy }}"  title="AMSCOPY" class="btn btn-default"><i class="fa fa-link"></i></button>
I don't know if the form is corect but I want to use this variable in a function.

Code: Select all

public function amscopy() {

		$this->load->model('catalog/product');
		$originalcode = $this->request->post['originalcode'];

.. 
}

New member

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by uksitebuilder » Wed Sep 25, 2019 10:46 pm

I don't see a form. I assume there is one surrounding that button and input field?

form action should be et on the form tag rather than on the button.

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by prototype0104 » Wed Sep 25, 2019 11:11 pm

Yeah.. I'm stupid.. Like this?

Code: Select all

<form action="{{ amscopy }}" method="get">
		<input type="text" name="originalcode" placeholder="Jan original" />
		
		<button type="submit" id="button-copyams" title="AMSCOPY" class="btn btn-default"><i class="fa fa-link"></i></button>
        </form>

New member

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by letxobnav » Wed Sep 25, 2019 11:43 pm

Code: Select all

<button type="submit" form="form-orig" id="button-copyams" data-toggle="tooltip" title="AMSCOPY" class="btn btn-default"><i class="fa fa-link"></i></button>
<form action="{{ amscopy }}" method="post" enctype="multipart/form-data" id="form-orig" class="form-horizontal">
	<input type="text" name="originalcode" placeholder="Jan original" />
</form>

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by uksitebuilder » Thu Sep 26, 2019 2:36 pm

prototype0104 wrote:
Wed Sep 25, 2019 11:11 pm
Yeah.. I'm stupid.. Like this?

Code: Select all

<form action="{{ amscopy }}" method="get">
		<input type="text" name="originalcode" placeholder="Jan original" />
		
		<button type="submit" id="button-copyams" title="AMSCOPY" class="btn btn-default"><i class="fa fa-link"></i></button>
        </form>
Yes, but as your controller function is looking for 'post' variables, you should set the form method to post instead of get also.

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom
Who is online

Users browsing this forum: thekrotek and 13 guests