Welcome Guest, Not a member yet? Register   Sign In
$ result does not shows in my view!!! HELP!!!
#1

[eluser]Bacu[/eluser]
I am stuck in this bug and I cannot solve it. I read already many times the user guide about form validation but I dont figure it out this problem. Please someone could help me. What I am doing wrong? I am using codeigniter 2.0.

Error: A PHP Error was encountered

Severity: Notice

Message: Undefined variable: result

Filename: views/home.php


My controller: form.php

Code:
class Form extends CI_Controller
{
  public function __construct()
  {
      parent::__construct();
        $this->load->model(‘signup_model’);
  }

  public function index()
  {
      $data[‘result’] =’‘;
    
      $this->load->library(‘form_validation’);

      $this->load->database();

      $this->form_validation->set_rules(‘email’, ‘Email’, ‘required|valid_email’, ‘E-mail is not vhttp://ellislab.com/forums/newtopic/51/alid!’);

      if ($this->form_validation->run() == FALSE)
      {
        $data[‘result’] = validation_errors();
        $this->load->view(‘home’, $data);
            }
      else
      {
        $data[‘result’] = $this->signup_model->create();
        $this->load->view(‘home’, $data);
          }
  }
}

My view: home.php

Code:
<form method=“post” action=“form”>
                Sign-up: <input type=“text” name=“email” value=”<?php echo set_value(‘email’); ?>” size=“30” />
                <input type=“hidden” name=“type” value=”<?php echo set_value(‘type’); ?>” size=“50” />
                <input type=“submit” class=“button” value=“Submit” /></p>
</form>
<span>&lt;?php echo $result; ?&gt;</span>
#2

[eluser]toopay[/eluser]
Is this your actual code?
Code:
...
$data[‘result’] =’‘;
...
&lt;form method=“post” action=“form”&gt;
If yes,
Code:
// replace every ’...‘ with '...', eg :
$data['result'] ='';
...
// replace every “...” with "...", eg :
&lt;form method="post" action="form"&gt;
#3

[eluser]Bacu[/eluser]
Thank you. I dont know What happened. I've just copy and paste. What Am I doing wrong?
I cannot figure it out. I am completly stuck.
Best wishes.


controller: form.php

Code:
class Form extends CI_Controller
{    
    public function __construct()
    {
        parent::__construct();
            $this->load->model('signup_model');
    }
    public function index()
    {
        $data['result'] ='';
        $this->load->library('form_validation');
        $this->load->database();
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email', 'E-mail is not valid!');
            if ($this->form_validation->run() == FALSE)
        {
                 $data['result'] = validation_errors();
                 $this->load->view('home', $data);
                   }
        else
        {
            // call model method DB
                $data['result'] = $this->signup_model->create();
                $this->load->view('home', $data);
                }
    }
}


view: home.php

Code:
&lt;form method="post" action="form"&gt;
                       <p class="space">Sign-up: &lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="30" /&gt;
                       &lt;input type="hidden" name="type" value="&lt;?php echo set_value('type'); ?&gt;" size="50" /&gt;
                       &lt;input type="submit" class="button" value="Submit" /&gt;&lt;/p>
                &lt;/form&gt;
                 <span>&lt;?php echo $result; ?&gt;</span>
#4

[eluser]toopay[/eluser]
I mean in your actual code, not here. Are you done replace any ’‘ with '', in your actual code?
#5

[eluser]Bacu[/eluser]
Yes! I did. I replaced all of them. :-(
My code are between because I received this advice from this forum. Is it right?
Thanks.

controller:: form.php
Code:
class Form extends CI_Controller
{    
    public function __construct()
    {
        parent::__construct();
            $this->load->model('signup_model');
    }
    public function index()
    {
        $data['result'] ='';
        $this->load->library('form_validation');
        $this->load->database();
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email', 'E-mail is not valid!');
            if ($this->form_validation->run() == FALSE)
        {
                 $data['result'] = validation_errors();
                 $this->load->view('home', $data);
                   }
        else
        {
            // call model method DB
                $data['result'] = $this->signup_model->create();
                $this->load->view('home', $data);
                }
    }
}

view:: home.php

Code:
&lt;form method="post" action="form"&gt;
<p class="space">Sign-up: &lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="30" /&gt;
&lt;input type="hidden" name="type" value="&lt;?php echo set_value('type'); ?&gt;" size="50" /&gt;
&lt;input type="submit" class="button" value="Submit" /&gt;&lt;/p>
&lt;/form&gt;
<span>&lt;?php echo $result; ?&gt;</span>
#6

[eluser]alexaaaaaaaaaa[/eluser]
Nope that's not right i don't have time to figure out what are you doing but from what i know the code should be something like
if butto
if it pass validation
$insertData = array();
$insertData['field_from_database'] = $this->input->post('field_from_form');
..as many you want
then
$this->your_model->your_function($insertData);
end if

also take notice that you might want just to be sure that you hit the exact controller
like this action="&lt;?php echo site_url('form'); ?&gt;" (good practice)

ps ... write this &lt;?php if(isset($data)) then echo ?&gt;
#7

[eluser]toopay[/eluser]
Code:
&lt;?php defined('BASEPATH') or die('No direct access script allowed');

class Form extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
        $this->load->model('signup_model');
    }

    public function index()
    {
        $data = array();
        $data['result'] ='';
        $this->load->library('form_validation');
        $this->load->database();
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email', 'E-mail is not valid!');
        if ($this->form_validation->run() == FALSE)
        {
            $data['result'] = (validation_errors()) ? validation_errors() : '';
            $this->load->view('home', $data);
        }
        else
        {
            // call model method DB
            $this->signup_model->create();
            $data['result'] =  'Successfully created!';
            $this->load->view('home', $data);
        }
    }
}
#8

[eluser]alexaaaaaaaaaa[/eluser]
look it'll allways say $result undefined ...becouse it's not ...it's when you fill the form that's why i told him look you must put a condition if(iseet($result)) echo $result;
my oppinion...
#9

[eluser]Luis ACE[/eluser]
I just tested your code & everything seems to be fine.
When do you get the error? before or after you submit the form?
#10

[eluser]Bacu[/eluser]
Luis! Thanks for your response. This erros is showed before. For example, I load the page www.myweb.local/home and this error is showed. I dont know what I am doing wrong.
Cheers!

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: result

Filename: views/home.php




Theme © iAndrew 2016 - Forum software by © MyBB