Post by JDECLEMENTI » Wed Feb 15, 2017 4:39 am

So I am Trying To create a Page where a user can enter in information into a form and it will email it to an email set in the file. I have created the template, controller and language file the problem i am having is whenever I submit the form it goes to a blank page and not the success page. is there something simple i am missing here? Opencart 2.0.2.0


employment.php

Code: Select all

<?php
class ControllerInformationEmployment extends Controller {
  private $error = array();
    
  public function index() {
    $this->language->load('information/employment'); //Optional. This calls for your language file

    $this->document->setTitle($this->language->get('heading_title')); //Optional. Set the title of your web page.

    if ($this->request->server['REQUEST_METHOD'] == 'POST') {
            $mail = new Mail();
            $mail->protocol = $this->config->get('config_mail_protocol');
            $mail->parameter = $this->config->get('config_mail_parameter');
            $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
            $mail->smtp_username = $this->config->get('config_mail_smtp_username');
            $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
            $mail->smtp_port = $this->config->get('config_mail_smtp_port');
            $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');

            $mail->setTo('employment@myserver.com.com');
            $mail->setFrom('test@test.com');
            $mail->setSender(html_entity_decode($this->request->post['fullname'], ENT_QUOTES, 'UTF-8'));
            $mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $data['fullname']), ENT_QUOTES, 'UTF-8'));

            $query = $data['fullname'];

            $mail->setText($query);
            $mail->send();
            $this->response->redirect($this->url->link('information/employment/success'));
        }
    
    $data['breadcrumbs'] = array();

    $data['breadcrumbs'][] = array(
      'text'      => $this->language->get('text_home'),
      'href'      => $this->url->link('common/home')
    );

    $data['breadcrumbs'][] = array(
      'text'      => $this->language->get('heading_title'),
      'href'      => $this->url->link('information/employment')
    );   
       
    $data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" from language file.
    $data['apply'] = $this->language->get('apply');
    $data['action'] = $this->url->link('information/Employment');
    
    $data['column_left'] = $this->load->controller('common/column_left');
    $data['column_right'] = $this->load->controller('common/column_right');
    $data['content_top'] = $this->load->controller('common/content_top');
    $data['content_bottom'] = $this->load->controller('common/content_bottom');
    $data['footer'] = $this->load->controller('common/footer');
    $data['header'] = $this->load->controller('common/header');


    if (isset($this->request->post['fullname'])) {
            $data['fullname'] = $this->request->post['fullname'];
        } else {
            $data['fullname'] = '';
        }

     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/employment.tpl')) { //if file exists in your current template folder
      $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/information/employment.tpl', $data)); //get it
    } else {
      $this->response->setOutput($this->load->view('default/template/information/employment.tpl', $data)); //or get the file from the default folder
    }     


    
  }
  
  	public function success() {
		$this->load->language('information/employment');

		$this->document->setTitle($this->language->get('heading_title'));

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/home')
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('heading_title'),
			'href' => $this->url->link('information/employment')
		);

		$data['heading_title'] = $this->language->get('heading_title');

		$data['text_message'] = $this->language->get('text_success');

		$data['button_continue'] = $this->language->get('button_continue');

		$data['continue'] = $this->url->link('common/home');

		$data['column_left'] = $this->load->controller('common/column_left');
		$data['column_right'] = $this->load->controller('common/column_right');
		$data['content_top'] = $this->load->controller('common/content_top');
		$data['content_bottom'] = $this->load->controller('common/content_bottom');
		$data['footer'] = $this->load->controller('common/footer');
		$data['header'] = $this->load->controller('common/header');

		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
			$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/success.tpl', $data));
		} else {
			$this->response->setOutput($this->load->view('default/template/common/success.tpl', $data));
		}
	}
  

}
employment.tpl

Code: Select all

<?php echo $header; ?>
<div class="container">
  <ul class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
    <?php } ?>
  </ul>
  <div class="row"><?php echo $column_left; ?>
    <?php if ($column_left && $column_right) { ?>
    <?php $class = 'col-sm-6'; ?>
    <?php } elseif ($column_left || $column_right) { ?>
    <?php $class = 'col-sm-9'; ?>
    <?php } else { ?>
    <?php $class = 'col-sm-12'; ?>
    <?php } ?>
    <div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
      


      
      
      
      <h1><?php echo $heading_title; ?></h1>
     
  <form action="<?php echo $action; ?>" enctype="multipart/form-data" method="post" name="quoteForm">



    <div class="form-group">
        <label class="control-label">Full Name</label>
        <input class="form-control" type="text" name="fullname" value="<?php echo $fullname?>" placeholder="<?php echo $fullname?>" /> 
        <?php if ($error_fullname) { ?>
        <div class="text-danger"><?php echo $error_fullname; ?></div>
        <?php } ?>
    </div>

    
    <div class="buttons">
        <input class="btn btn-primary btn-small btn-block" type="submit" value="<?php echo $apply; ?>"  id="apply" class="button" />
    </div>

</form>
    
      <?php echo $content_bottom; ?></div>
    <?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?> 

Newbie

Posts

Joined
Fri Jan 20, 2017 11:51 pm
Who is online

Users browsing this forum: No registered users and 102 guests