Jump to content

Recommended Posts

i've tried whit a lot of solutions from other posts but nothing seems to be working 

this part is where im having trouble but i dont know how to get it to work
```
        $this->load->library('form_validation');
        $this->load->library('form');
```


Controler
```
    <?php

namespace App\Controllers;

class Home extends BaseController
{
  public function __contruct()
{
    parent::__construct();// you have missed this line.
    
}
    public function index()
    {
        helper (['form']);
        return view('inicio');
    }
    public function descarga()
    {
        return view('filesnames');
    }
    public function conta()
    {
        $this->load->library('form_validation');
        $this->load->library('form');
        return view('contact/index');
    }
    public function pregu()
    {
        return view('preguntas');
    }
    public function dud(){
        return view('duda');
    }
    public function contact()
    {
    
        $autoload['libraries'] = array('session','Email','form','form_validation');
        $autoload['helper']=array('form', 'url');

    //Set form validation
    $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[3]|max_length[20]');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|min_length[0]|max_length[60]');
    $this->form_validation->set_rules('message', 'Message', 'trim|required|min_length[5]|max_length[200]');

    //Run form validation
    if ($this->form_validation->run() === FALSE)
    {
        $this->load->view('contacto');
    } else {

        //Get the form data
        $name = $this->input->post('name');
        $from_email = $this->input->post('email');
        $subject = $this->input->post('subject');
        $message = $this->input->post('message');

        //Web master email
        $to_email = 'admin@domain.com'; //Webmaster email, who receive mails

        //Mail settings
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_port'] = '465';
        $config['smtp_user'] = 'mail@domain.com'; // Your email address
        $config['smtp_pass'] = 'mailpassword'; // Your email account password
        $config['mailtype'] = 'html'; // or 'text'
        $config['charset'] = 'iso-8859-1';
        $config['wordwrap'] = TRUE; //No quotes required
        $config['newline'] = "\r\n"; //Double quotes required

        $this->email->initialize($config);                        

        //Send mail with data
        $this->email->from($from_email, $name);
        $this->email->to($to_email);
        $this->email->subject($subject);
        $this->email->message($message);
        
        if ($this->email->send())
        {
            $this->session->set_flashdata('msg','<div class="alert alert-success">Mail sent!</div>');

            redirect('contact');
        } else {
            $this->session->set_flashdata('msg','<div class="alert alert-danger">Problem in sending</div>');
            $this->load->view('contacto');
        }

    }
  }
}
```
view
```
    <body class="ecommerce">

  <div class="header">
    <div class="container">
      <a class="site-logo" href="<?= site_url('/'); ?>"><img src="assets/images/home/logou2.png" class="logosi" alt=""></a>

      <a href="javascript:void(0);" class="mobi-toggler"><i class="fa fa-bars"></i></a>
    </div>

    <!-- BEGIN NAVIGATION -->
    <div class="header-navigation">
      <ul>
        <li><a href="<?= site_url('/'); ?>">Inicio</a></li>
        <li><a href="<?php base_url()?>Asistentev16.apk" download="Asistentev16.apk">Descargar</a></li> 
        <li><a href="<?= site_url('/cont'); ?>">Contactanos</a></li>   
        <li><a href="<?= site_url('/faq'); ?>">Preguntas Frecuentes</a></li>         
        </ul>
    </div>
  </div><br>
<div class="container">
<h2>Contact</h2>
<div class="row">
  <?php $validation =  \Config\Services::validation(); ?>
    <div class="col-lg-6">
        <?php echo $_SESSION['msg']; ?>
        <form action="<?php echo base_url('/submit-form') ?>" method="post">
        <div class="form-group">Nombre
            <?php echo form_input(array('name' => 'name', 'id' => 'name', 'size' => '50', 'value' => set_value('name'))) ?>
            <?php if ($validation->getError('name')): ?>
               <div class="invalid-feedback">
                  <?= $validation->getError('name') ?>
               </div>                                
            <?php endif; ?>
        </div>
        <div class="form-group">Email
            <?php echo form_input(array('email' => 'email', 'id' => 'email', 'size' => '50', 'value' => set_value('email'))) ?>
            <?php if ($validation->getError('email')): ?>
               <div class="invalid-feedback">
                  <?= $validation->getError('email') ?>
               </div>                                
            <?php endif; ?>
        </div>
        <div class="form-group">Asunto
            <?php echo form_input(array('subject' => 'subject', 'id' => 'subject', 'size' => '50', 'value' => set_value('subject'))) ?>
            <?php if ($validation->getError('subject')): ?>
               <div class="invalid-feedback">
                  <?= $validation->getError('subject') ?>
               </div>                                
            <?php endif; ?>
        </div>
        <div class="form-group">Mensaje
            <?php echo form_input(array('message' => 'message', 'id' => 'message', 'value' => set_value('message'))) ?>
            <?php if ($validation->getError('message')): ?>
               <div class="invalid-feedback">
                  <?= $validation->getError('message') ?>
               </div>                                
            <?php endif; ?>
        </div>
        <button name="submit" type="submit" class="btn btn-primary" />Send</button>
        </form>
    </div>
</div>
</body>
```

I'm assuming the issue is within the class "BaseController". Is that where the methods load and library are defined? It would seem to me that the call to 'load' is returning null instead of an object, which causes the error when the 'library' method is called.

41 minutes ago, Psycho said:

I'm assuming the issue is within the class "BaseController". Is that where the methods load and library are defined? It would seem to me that the call to 'load' is returning null instead of an object, which causes the error when the 'library' method is called.

what should i do?

im a noob programing php and codeigniter

Edited by vegabson

It looks like you're mixing versions of CodeIgniter - version 3 used load() while version 4 uses namespaces. I'm pretty sure there's an upgrade doc somewhere (it's been a bit since I've worked with CI so I don't remember specifically).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.