Upload resume file upload and send email in opencart

Job_Application Twig file content

{{ header }}
<style>
  input#input_resume{
  border: none;
  border-radius: none;
  outline-style: none;
  box-shadow: none;
  -webkit-box-shadow:none;
  }
    .bgimage{
        /* background-image: url("F:/instaDiet/march/bg.jpg");
        background-color: rgb(255, 255, 255);
        opacity: 50%; */
        position: relative;
        z-index: 5;
    }

    .bgimage::after{
        content: "";
        position: absolute;
        background-image: url("F:/instaDiet/march/bg.jpg");
        opacity: .7;
        z-index: 2;
        left: 0px;
        top: 0px;
        display: block;

    }
          .gen{
    margin-left: -15px;
    margin-right: -15px;
  }
  
            textarea.form-control {
    height: 110px;
}
    h1.bredcrump-head.text-center{
       display: none;
       }
                #landing1 i {
                    position: absolute;
                }
    
    
                #landing1 button.btn.btn-xl {
                    margin: 0px;
                    border-radius: 6px;
                }
    
                #landing .logo-icon li {
                    padding-right: 20px;
                }
    
                #landing .logo-icon li p {
                    font-size: 10px;
                }
    
                #landing1 .f {
                    padding-left: 15px;
                    padding-right: 15px;
                    padding-top: 6px;
                }
    
                #landing1 .f ul li {
                    font-size: 15px;
                    letter-spacing: 2px;
                    padding-bottom: 30px;
                    font-weight: 600;
                    color: #000;
                    max-width: 500px;
                    list-style: none;
                    padding-left: 30px;
                    padding-right: 0px;
                }
    
                #landing1 .f button.btn.btn-default.btn-xl.btn.btn-default.product-btn.bold {
                    margin-top: 6px;
                }
    
                @media only screen and (max-width: 767.98px) {
    
                    #landing1 .f ul li {
                        padding-left: 10px;
                        padding-right: 0px;
                    }
                }
    
                .diet {
    
                    margin-top: 20px;
  					
                   
    
                }
                .formmargin{
              		margin-top: 12px;
              }
  
               {# .diet:hover {
                    transform: scale(1.1); #}
    
                }
    
                .dietcontent {
                    float: right;
                }
    
                p {
                    font-family: 'sf-ui-display-light';
                }
            </style>

{{ content_top }}
 <section id="landing1" class="content" style="background-color:white;">
        
        <div class="container-fluid ">
            <div class="row">
               
                    <div class="col-md-12 col-xs-12 text-center">
                       
                              <h1 class=""><b>Apply For The Job!</b></h1>
                           
                    </div>

               


            </div>
       
        
            <div class="row">
                
                    <div>
                        <div class="col-md-6 col-md-offset-1 col-sm-12 col-xs-12">
                          <!-- <img src="https://www.instadiet.in/image/detention.jpg" alt="Pineapple" class="diet img-responsive"> -->
                          <p><strong>Job Role:</strong></p>
                          <ul>
                              <li>The Production Engineer (PE) is responsibile or managing, monitoring, and configuring the applications on staging and production systems.</li>
                              <li>should be able modify scripts,worked on python scripting OR Hands on coding experience in python</li>
                              <li>Together with your engineering team, will share an on-call rotation and be an escalation contact for service incidents</li>
                              <li>Debugs and fix hard problems in live production </li>
                              <li>Experience in AWS Infrastructure</li>
                          </ul>
                          <p><strong>Skills and Qualification:</strong></p>
                          <ul>
                              <li>4+ years of industry or open source experience.</li>
                              <li>Worked collaboratively on a software development team</li>
                          </ul>
                          <p><strong>Look forward to::</strong></p>
                          <ul>
                              <li>Working with a world-class team. </li>
                              <li>Fun &amp; work at the same place with an amazing work culture and flexible timings.</li>
                              <li>Get ready to transform yourself into a health junkie</li>
                              
                          </ul>
                          
                            <!-- <h2 class="text-center"><span style="font-size: 16px;">Ms. Mili Sethi, Head of Nutrition and Dietetics</span></h2>
                            <p class="text-light text-center" style="font-size: 12px; ">She holds a Postgraduate Degree in Dietetics and Food Service Management. Has Experience of 20 years in Weight management and Healthcare Industry. She has worked in Hospitals 
                          as a Clinical Nutritionist Planning Therapeutic Diets for patients as well as Balanced Diet for Weight loss.</p> -->
                                                    </div>
                        <div class="col-md-3 col-md-offset-1 col-sm-12 col-xs-12" id="appoint">
                            
                            <form action="{{ action }}" method="post" enctype="multipart/form-data" class="form-horizontal formmargin">
                                <div class="form-group">
                                    <div class="col-md-12 col-sm-12 mb-s">
                                        <!-- <i class="fa fa-user icon"></i> -->
                                        <label for="">
                                            <h6><b>Name*</b></h6>
                                        </label>
                                        <input required="" type="text" name="name" value="" id="input-name" class="form-control border bold">
                                        <p id="namecheck"></p>
                                    </div>
                                </div>
                                 <div class="form-group">
                                    <div class="col-md-12 col-sm-12 mb-s">
                                        <label for="">
                                            <h6><b>Email*</b></h6>
                                        </label>
                                        <!-- <i class="fa fa-envelope icon"></i> -->
                                        <input required="" type="text" name="email" value="" id="input_email" class="form-control border bold">
                                        <p id="emailcheck"></p>
                                    </div>
                                </div>
                                 <div class="form-group">
                                    <div class="col-md-12 col-sm-12 mb-s">
                                        <label for="">
                                            <h6><b>Phone*</b></h6>
                                        </label>
                                        <!-- <i class="fa fa-phone icon"></i> -->
                                        <input required="" type="text" name="telephone" value="" id="input_phone" class="form-control border bold">
                                        <p id="phonecheck"></p>
                                      
                                    </div>
                                </div>
                           <div class="form-group">
                                    <div class="col-md-12 col-sm-12 col-xs-12 mb-s">
                                        <label for="">
                                            <h6><b>Post</b></h6>
                                        </label>
                                        <select required="" type="text" name="post_applied" value="" id="input-job" class="form-control border bold">
                                              <option selected value="">Select Post</option>  
                                              <option value="1">iOS Devoloper</option>
                                              <option value="2">Php Devoloper</option>
                                              <option value="3">Android Devoloper</option>
                                              <option value="4">Software Tester</option>
                                              <option value="5">Web Designer</option>
                                              <option value="6">Head Of Operations</option>
                                              <option value="7">Marketing Manager</option>
                                              <option value="8">Marketing Analyst</option>
                                              <option value="9">Jr. Graphic Designer</option>
                                              <option value="10">UI/UX Designer</option>
                                              <option value="11">IT and Sales Recruiter</option>
                                              </select>
                                              <p id="postcheck"></p>
                                    </div>
                                </div>
                                  <!--<div class="form-group">
                                    <div class="col-md-6 col-sm-6 col-xs-6 mb-s">
                                        <label for="">
                                            <h6><b>Age(Yrs)*</b></h6>
                                        </label>
                                        <input required="" type="number" min="0" name="age" value="" id="input_age" class="form-control border bold">
                                        <p id="agecheck"></p>
                                    </div>
                                </div> -->
                               
                               
                                <div class="form-group">
                                    <div class="col-md-12 col-sm-12 mb-s">
                                        <label for="">
                                            <h6><b>Resume*</b></h6>
                                        </label>
                                        <button type="button" id="button-upload" data-loading-text="Uploading.." class="btn btn-default btn-block"><i class="fa fa-upload"></i> &nbsp; </button>
        <input type="hidden" name="file" value="" id="file"/>
                                        <p id="msgcheck"></p>
                                    </div>
                                </div>
                                <div class="form-group text-center">
                                    <div class="col-md-12 col-sm-12">
                                    <input type="hidden" name="subject" value="Job Application">
                     <input type="hidden" name="redirect" value="job-application" >
                      <input type="hidden" name="enquiry" value="job-application" >
                      {% if success %} 
                 <div class="valid col-sm-12" id="close-btn1"><div class="success_inline alert alert-success">{{ success }}<button type="button" class="close" data-dismiss="alert">×</button></div></div>
                     {% endif %}
                                        <button type="submit" id="scrollbtn" class="btn btn-xl btn btn-default bold " value="Submit">Submit</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!--end of both section -->
            
            </div>
        </div>
    </section>
    <script>
        $(document).ready(function () {
      
                  $('#namecheck').hide();
                  $('#emailcheck').hide();
                  $('#phonecheck').hide();
                 // $('#msgcheck').hide();
                 // $('#agecheck').hide();
                  $('#postcheck').hide();
      
                  var user_err = true;
                  var email_err = true;
                  var phone_err = true;
                  //var msg_err = true;
                  //var age_err = true;
                  var job_err = true;
                $('#scrollbtn').click(function () {
      
                       var user_err = true;
                       var email_err = true;
                       var phone_err = true;
                       //var msg_err = true;
                      // var age_err = true;
                       var job_err = true;
      
                      name_check();
                       email_check();
                       telephone_check();
                      // msg_check();
                       //age_check();
                       job_check();
      
                  function name_check() {
                      var user_val = $('#input-name').val();
                      if (user_val.length == '') {
                          $('#namecheck').show();
                          $('#namecheck').html("*Please Enter Your Name");
                          $('#namecheck').focus();
                          $('#namecheck').css({"color":"red" , "font-size": "10px"});
                          user_err = false;
                          return false;
                      }
                      else if ((user_val.length < 3) || (user_val.length > 32 )){
                            $('#namecheck').show();
                          $('#namecheck').html("*Name must be between 3 and 32 characters!");
                          $('#namecheck').focus();
                          $('#namecheck').css({"color":"red", "font-size": "10px"});
                          user_err = false;
                          return false;
                      }
                      else {
                          $('#namecheck').hide();
                      }
                  }
      
                   function email_check() {
                      
                      var email_val = $('#input_email').val();
                      var regex =  /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                      if (regex.test(email_val)) {
                          $('#emailcheck').hide();
                          email_err = true;
                          return true;
                      }
      
                      else if (email_val.length == ''){
                          
                          
                          $('#emailcheck').show();
                          $('#emailcheck').html("*Please enter email address!");
                          $('#emailcheck').focus();
                          $('#emailcheck').css({"color":"red", "font-size": "10px"});
                          email_err = false;
                          return false;
                      }
                      else {
                         
                          $('#emailcheck').show();
                          $('#emailcheck').html("*Please enter valid email characters!");
                          $('#emailcheck').focus();
                          $('#emailcheck').css({"color":"red", "font-size": "10px"});
                          email_err = false;
                          return false;
                         
                      }
                  }
      
                   function telephone_check (){
                      var phone_val = $('#input_phone').val();
                      var phoneno = /[0-9]{10}/;
                      if (phoneno.test(phone_val)){
                          $('#phonecheck').hide();
                          phone_err = true;
                          return true;
                      }
                      else if(phone_val.length == " ") {
                          $('#phonecheck').show();
                          $('#phonecheck').html("*Phone no must be valid!");
                          $('#phonecheck').focus();
                          $('#phonecheck').css({"color":"red", "font-size": "10px"});
                          phone_err = false;
                          return false;
                      }
                      else {
                          $('#phonecheck').show();
                          $('#phonecheck').html("*Please enter valid phone number!");
                          $('#phonecheck').focus();
                          $('#phonecheck').css({"color":"red", "font-size": "10px"});
                          phone_err = false;
                          return false;
                      }
      
                  }
                  

                  function job_check() {
                      var job_val = $('#input-job').val();
                      //    alert(email_val);
      
                      if (job_val.length == '') {
                          $('#postcheck').show();
                          $('#postcheck').html("*Required ");
                          $('#postcheck').focus();
                          $('#postcheck').css({"color":"red", "font-size": "10px"});
                          job_err = false;
                          return false;
                      }
                    // else if ((gender_val.length < 10) || (msg_val.length > 3000)) {
                    //       $('#gendercheck').show();
                    //       $('#gendercheck').html("*Enquiry must be between 10 and 3000 characters!");
                    //       $('#gendercheck').focus();
                    //       $('#gendercheck').css({"color":"red"});
                    //       gender_err = false;
                    //       return false;
                    //   }
                      else {
                          $('#postcheck').hide();
                      }
                  }
                 

      
                      if ((user_err == true) && (email_err == true) && (phone_err == true) && (job_err == true)) {
                          return true;
                      } else {
                          return false;
                      }
                      
                  });
      
              });
      </script>
<script>
    $('button[id^=\'button-upload\']').on('click', function() {
        var node = this;

        $('#form-upload').remove();

        $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');

        $('#form-upload input[name=\'file\']').trigger('click');

        timer = setInterval(function() {
            if ($('#form-upload input[name=\'file\']').val() != '') {
                clearInterval(timer);

                $.ajax({
                    url: 'index.php?route=tool/upload',
                    type: 'post',
                    dataType: 'json',
                    data: new FormData($('#form-upload')[0]),
                    cache: false,
                    contentType: false,
                    processData: false,
                    beforeSend: function() {
                        $(node).button('loading');
                    },
                    complete: function() {
                        $(node).button('reset');
                    },
                    success: function(json) {
                        $('.text-danger').remove();

                        if (json['error']) {
                            $(node).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>');
                        }

                        if (json['success']) {
                            alert(json['success']);

                            $(node).parent().find('input').attr('value', json['code']);
                        }
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                    }
                });
            }
        }, 500);
    });
</script>
{{ footer }}

Job_Application Controller file content

<?php
class ControllerInformationJobApplication extends Controller {
	public function index() {
		//$this->load->language('information/tracking');

		$this->document->setTitle("Job Application");
		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/home')
		);
		if(empty($this->session->data['success'])){
$data['success']='0';
		}else{
			$data['success']=$this->session->data['success'];	
		}
		$details=$this->load->controller('common/location');
		$data['countryCode']=$details->countryCode;
		$data['region']=$details->region;
		$data['city']=$details->city;
		$data['action'] = $this->url->link('information/contact', '', true);
		$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/footer1');
		$data['header'] =$this->load->controller('common/header1');

		$this->response->setOutput($this->load->view('information/job_application', $data));
	}
	
	
}

Update information/contact controller

<?php
class ControllerInformationContact extends Controller {
	private $error = array();
	private $post_applied=array("1"=>"iOS Devoloper","2"=>"Php Devoloper","3"=>"Android Devoloper","4"=>"Software Tester","5"=>"Web Designer","6"=>"Head Of Operations","7"=>"Marketing Manager","8"=>"Marketing Analyst","9"=>"Jr. Graphic Designer","10"=>"UI/UX Designer","11"=>"IT and Sales Recruiter");
	public function index() {
		$this->load->language('information/contact');

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

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$mail = new Mail($this->config->get('config_mail_engine'));
			$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($this->config->get('config_email'));
			$mail->setTo('ankit@instadiet.in');
			$mail->setFrom($this->config->get('config_email'));
			$mail->setReplyTo($this->request->post['email']);
			$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
			$mail->setSubject(html_entity_decode(sprintf($this->request->post['subject'], $this->request->post['name']), ENT_QUOTES, 'UTF-8'));//$this->language->get('email_subject')
			$telephone='';
			if(isset($this->request->post['telephone'])){
				$telephone="Telephone: ".$this->request->post['telephone']."\n";
			}
			if(isset($this->request->post['post_applied'])){
				$telephone.="Post Applied: ".$this->post_applied[$this->request->post['post_applied']]."\n";
			}
			$mail->setText($telephone.$this->request->post['enquiry']);
			
			if(isset($this->request->post['file']) && $this->request->post['file']){
				$this->load->model('tool/upload');
				$upload_info = $this->model_tool_upload->getUploadByCode($this->request->post['file']);
				$phyname = DIR_UPLOAD.$upload_info['filename'];
				$temp_name = DIR_UPLOAD.$upload_info['name'];
				copy($phyname,$temp_name);
				$mail->AddAttachment($temp_name);
				
			  }
		  
			  $mail->send();
			  if(isset($temp_name)){
			   unlink( $temp_name );
			  }
			//$mail->send();
if(isset($this->request->post['redirect']))
{
	$redirect=$this->request->post['redirect'];
	$this->session->data['success']="Your query has been successfully submitted. one of our InstaDiet executive will contact you shortly.";
	//$this->response->redirect($this->url->link($redirect));
	$this->response->redirect($redirect);
}else{$this->response->redirect($this->url->link('information/contact/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/contact')
		);

		if (isset($this->error['name'])) {
			$data['error_name'] = $this->error['name'];
		} else {
			$data['error_name'] = '';
		}

		if (isset($this->error['email'])) {
			$data['error_email'] = $this->error['email'];
		} else {
			$data['error_email'] = '';
		}

		if (isset($this->error['enquiry'])) {
			$data['error_enquiry'] = $this->error['enquiry'];
		} else {
			$data['error_enquiry'] = '';
		}

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

		$data['action'] = $this->url->link('information/contact', '', true);

		$this->load->model('tool/image');

		if ($this->config->get('config_image')) {
			$data['image'] = $this->model_tool_image->resize($this->config->get('config_image'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_height'));
		} else {
			$data['image'] = false;
		}

		$data['store'] = $this->config->get('config_name');
		$data['address'] = nl2br($this->config->get('config_address'));
		$data['geocode'] = $this->config->get('config_geocode');
		$data['geocode_hl'] = $this->config->get('config_language');
		$data['telephone'] = $this->config->get('config_telephone');
		$data['fax'] = $this->config->get('config_fax');
		$data['open'] = nl2br($this->config->get('config_open'));
		$data['comment'] = $this->config->get('config_comment');

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

		$this->load->model('localisation/location');

		foreach((array)$this->config->get('config_location') as $location_id) {
			$location_info = $this->model_localisation_location->getLocation($location_id);

			if ($location_info) {
				if ($location_info['image']) {
					$image = $this->model_tool_image->resize($location_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_height'));
				} else {
					$image = false;
				}

				$data['locations'][] = array(
					'location_id' => $location_info['location_id'],
					'name'        => $location_info['name'],
					'address'     => nl2br($location_info['address']),
					'geocode'     => $location_info['geocode'],
					'telephone'   => $location_info['telephone'],
					'fax'         => $location_info['fax'],
					'image'       => $image,
					'open'        => nl2br($location_info['open']),
					'comment'     => $location_info['comment']
				);
			}
		}

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

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

		if (isset($this->request->post['enquiry'])) {
			$data['enquiry'] = $this->request->post['enquiry'];
		} else {
			$data['enquiry'] = '';
		}
		if(!isset($this->request->post['telephone'])){
		// Captcha
		if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
			$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'), $this->error);
		} else {
			$data['captcha'] = '';
		}
	}

		$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/footer1');
		$data['header'] = $this->load->controller('common/header1');

		$this->response->setOutput($this->load->view('information/contact', $data));
	}

	protected function validate() {
		if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
			$this->error['name'] = $this->language->get('error_name');
		}
		if (isset($this->request->post['telephone']) && ((utf8_strlen($this->request->post['telephone']) < 10) || (utf8_strlen($this->request->post['telephone']) > 13))) {
			$json['error']['telephone'] = "Valid mobile required";
		}
		if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
			$this->error['email'] = $this->language->get('error_email');
		}

		if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
			$this->error['enquiry'] = $this->language->get('error_enquiry');
		}
		if(!isset($this->request->post['telephone'])){
				// Captcha
		if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
			$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');

			if ($captcha) {
				$this->error['captcha'] = $captcha;
			}
		}
		}
	

		return !$this->error;
	}

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

		$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/contact')
		);
		$data['heading_title']="Enquiry Submitted";
		$data['text_message']=$this->language->get('text_success');
		$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/footer1');
		$data['header'] = $this->load->controller('common/header1');

		$this->response->setOutput($this->load->view('common/success', $data));
	}
}


Leave a Reply