• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form validation error

#11
[eluser]the_unforgiven[/eluser]

Code:
&lt;?php echo validation_errors('<div class="error">', '</div>'); ?&gt;
  &lt;?php echo form_open('contact/send'); ?&gt;
  &lt;?php
  echo "<p><label for='name'>Name</label><br/>";
  $data = array('name'=>'name','id'=>'name','size'=>25);
  echo form_input($data) ."</p>";
  
  echo "<p><label for='phone'>Phone</label><br/>";
  $data = array('name'=>'phone','id'=>'phone','size'=>25);
  echo form_input($data) ."</p>";
  
  echo "<p><label for='email'>Email:</label><br/>";
  $data = array('name'=>'email','id'=>'email','size'=>25);
  echo form_input($data) ."</p>";
  
  echo "<p><label for='message'>Requirements/Message:</label><br/>";
  $data = array('name'=>'message','id'=>'message','size'=>25);
  echo form_textarea($data) ."</p>";
  ?&gt;
  <br />
  &lt;input type="submit" name="submit" class="submit" value="Send" /&gt;
  &lt;?php
  echo form_close();
  ?&gt;

#12
[eluser]Mauricio de Abreu Antunes[/eluser]
[quote author="the_unforgiven" date="1330507397"]Hi All,

I'm getting this error:

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/Form_validation.php
Line Number: 320

Fatal error: Call to a member function load() on a non-object in /home/site/public_html/system/libraries/Form_validation.php on line 320

Here's the controller
Code:
function send()
{

  // Set Validation Rules
  $this->form_validation->set_rules('name', 'Name', 'required');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  $this->form_validation->set_rules('phone', 'Phone', 'trim|required');
  $this->form_validation->set_rules('message', 'Message', 'trim|required');
  
  // Validation runs false rteun back to form and show errors
  if ($this->form_validation->run() == FALSE) {
  
   $this->index();
  }
  // If everything is filled out with no errors procced with sending the form to email and database
  else {
                 echo 'Submitted';
                }
}

I have tried commenting out line by line but still no joy then if i comment out them all it does kinda work, just wondering why this is not working can anyone shed some light on this for me?

Help much appreciated.[/quote]

Try to comment out $this->index() and echo 'Submitted'.

#13
[eluser]the_unforgiven[/eluser]
By commenting out those lines will doing nothing.

#14
[eluser]the_unforgiven[/eluser]
Full controller incl index function

Code:
function index()
{
$data['title'] = 'Contact us';
$data['email'] = $this->input->post('email');

$data['main_content'] = 'contact';
    $this->load->view('template', $data);
}

// Send mail from form
function send()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');

// Set Validation Rules
$this->form_validation->set_rules('name' , 'Name' , '');
$this->form_validation->set_rules('email' , 'Email' , 'valid_email');
$this->form_validation->set_rules('phone' , 'Phone' , '');
$this->form_validation->set_rules('message' , 'Message' , '');
  
// Validation runs false return back to form and show errors
if ($this->form_validation->run() == FALSE) {
  
  $this->index();
  
}
// If everything is filled out with no errors proceed with sending the form to email and database
else {
$name = $this->input->post('name');  
$email = $this->input->post('email');

$message = "Hey guys, someone has requested a quote or left a message via the  website:" . "\n\r\n";
$message .= "Name:". $this->input->post('name') . "\n";
$message .= "Email:". $this->input->post('email') . "\n";
$message .= "Phone:". $this->input->post('phone') . "\n";
$message .= "Message:". $this->input->post('message');

$this->email->from($email, $name);
$this->email->to('me@email.com');
$this->email->subject('Quote/Message Request');
$this->email->message($message);
$this->email->send(); // Send the message function to the persons email address
$this->email->clear(); // Clears the form ready for another submission

$data['title'] = 'Thank you, Message received. ';
$data['description'] = '.';
$data['keywords'] = '';
$data['main_content'] = 'thanks';
    $this->load->view('template', $data);

}
}

So you can see everything it worked locally but when I uploaded to server it starting throwin the error in first post out....

#15
[eluser]Mauricio de Abreu Antunes[/eluser]
Hum, is this working in your localhost, but in your server not?
There is another controller using form_validation?

#16
[eluser]the_unforgiven[/eluser]
only this page using form_validation and like I said it worked locally, so not sure why it doesn't now on the server.

#17
[eluser]Matalina[/eluser]
Do you have langauge files?

The line throwing the error:
Code:
// Load the language file containing error messages
$this->CI->lang->load('form_validation');

#18
[eluser]Mauricio de Abreu Antunes[/eluser]
What CI versions are you using?
It's so mad, because i don't see any errors in your code, sorry.

#19
[eluser]the_unforgiven[/eluser]
[quote author="Matalina" date="1330535507"]Do you have langauge files?

The line throwing the error:
Code:
// Load the language file containing error messages
$this->CI->lang->load('form_validation');
[/quote]

Yes lang files all there

#20
[eluser]the_unforgiven[/eluser]
Yes i know i dont see any errors in my code either and done this at least 50 times in last 2 month CI version is latest 2.1.0


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.