I think this is basic problem for open cart, but I cant fix it, in view I put 1 field head_text_field
then i put to variable in controller then use var_dump
for check value
This for View :
<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a href="<?php echo $cancel; ?>" class="button"><?php echo $button_cancel; ?></a></div>
</div>
<div class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_head; ?></td>
<td><input type="text" name="head_text_field" value="<?php echo $head_text_field; ?>" placeholder="Input Head Text" size="40"/></td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php echo $footer; ?>
Controller:
<?php
class ControllerItemItem extends Controller {
private $error = array();
public function index() {
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->getList();
}
protected function getList(){
if (isset($this->request->get['head_text_field'])){
$head_text_field = $this->request->get['head_text_field'];
var_dump($head_text_field); exit; // VAR_DUMP HERE
} else {
$head_text_field = null;
echo "FAILED"; // FAILED HERE
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/item', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_head'] = $this->language->get('entry_head');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['action'] = $this->url->link('item/item/insert', 'token=' . $this->session->data['token'], 'SSL');
$this->data['token'] = $this->session->data['token'];
$this->template = 'item/item.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function insert()
{
var_dump($head_text_field); exit;
}
}
?>
When I try input, result is FAILED?? Where I did mistake? for model I not call or use it right now in controller.
EDIT 1 Sorry i add function insert for make it not error (for button insert in controller bottom)
If you want to get any variable
from opencart controller
in your view then you need to pass this variable as below:
Controller File
if (isset($this->request->post['head_text_field'])){
$this->data['head_text_field'] = $this->request->get['head_text_field']; // Your variable
var_dump($this->data['head_text_field']); exit; // VAR_DUMP HERE
} else {
$this->data['head_text_field'] = null;
echo "FAILED"; // FAILED HERE
}
Now you can get head_text_field
in your view file as $head_text_field
.
Edit
public function insert()
{
if (($this->request->server['REQUEST_METHOD'] == 'POST')) {
echo $this->request->post['head_text_field']; // Your field value
}
}