Validation form in Codeigniter - error in class - codeigniter

I get error when Codeigniter does validation of form:
Fatal error: Call to a member function load() on a non-object in
/system/libraries/Form_validation.php on line 320
This is full code:
$this->form_validation->set_rules('lang', 'Lang', 'required|integer');
$this->form_validation->set_rules('subject', 'Subject', 'required|trim|min_length[5]');
$this->form_validation->set_rules('text', 'Body text', 'required|trim|min_length[5]');
$this->form_validation->set_error_delimiters('<li class="errorLi">', '</li>');
if ($this->form_validation->run() == FALSE) {
}
I get error on line $this->form_validation->run().
Also form_validation there is in autoload in CI.

Related

JetStream + Inertia - Uncaught (in promise) TypeError: can't access property "dataset", l is null

I've installed Jetstream with Inertia.
I'm trying to use standard blade view within the Laravel controller:
public function index()
{
$events = GameEvent::with('game')->limit(10)->orderBy('created_at')->get();
return view('index', ['events' => $events]);
}
}
But I'm getting the following error in the JS console:
Uncaught (in promise) TypeError: can't access property "dataset", l is null
Any idea how to solve this?

Laravel Jetstream Route Test With Inertia Returns Error Code 500

Out the test it works, I can visit the page and the controller wroks fine. I wrote the following test:
public function test_logged_user_is_not_redirected()
{
PartnerFactory::new()->create();
$request = $this->actingAs(UserFactory::new()->create())
->get('partners')
->assertRedirect('partners');
dd($request->inertiaProps());
}
I get error code 500. This is the controller:
public function index()
{
return Inertia::render('Partners/Index', [
'filters' => \Illuminate\Support\Facades\Request::all($this->getFilters()),
'contacts' => function() {
return $this->getAllContacts();
}
]);
}
This is the route in web.php
Route::get('partners', [PartnersController::class, 'index'])
->name('partners')
->middleware('auth');
Using refresh database, tried url with a '/' before, I still get 500.
edit: without exception handling i get: Trying to get property 'id' of non-object
Found the solution: The user in jetstream MUST have the personal team!

Undefined offset: 0 when using ->with_input() - laravel

I'm getting this error when using with_input() to keep the user old input data after submiting with validation errors:
ErrorException
Undefined offset: 0
the code for redirect is:
return Redirect::to('login')->with_input();
I am not sure which version of Laravel you are using, but your code should be:
return Redirect::to('login')->withInput();
and if you are returning errors too, you might consider using withErrors() in addition:
Route::post('register', function()
{
$rules = array(...);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('register')->withErrors($validator);
}
});
Check the docs:
http://laravel.com/docs/validation#error-messages-and-views
If you're using Laravel 4, you need to use withInput instead of with_input

Class 'JTable' not found

I am using Joomla 2.5.11 . I have a php file stored in the /public_html/joomtest/components/com_jumi/files which is pasted below.
I have a PHP form which is stored in the same location i.e /public_html/joomtest/components/com_jumi/files.
I want the PHP form to call the PHP script so that an article is created in Joomla. But whenever the PHP script is called, I receive the below error
Fatal error: Class 'JTable' not found
and the line on which Joomla throws error is
$table = JTable::getInstance('Content', 'JTable', array());
PHP script
<?php
$table = JTable::getInstance('Content', 'JTable', array());
$data = array(
'catid' => 8,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 0,
);
if (!$table->bind($data))
{
$this->setError($table->getError());
return false;
}
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
if (!$table->store())
{
$this->setError($table->getError());
return false;
}
?>
</body>
</html>
I tried putting in
require_once('/libraries/joomla/database/table.php');
but this again didnt work. Please help.
You need to define path of table file you want to use. Use the following code for include the specific table. For example:
JTable::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'tables');
And then call your table like below:
$con_table = JTable::getInstance('Content', 'JTable', array());
Hope this will work. Good Luck.

CodeIgniter reCaptcha and Form_validation class

I have a simple contact form with several required fields which is working fine. I am trying to add reCaptcha to the form for some added spam protection.
I have the reCaptcha displaying on the form correctly, I have my keys installed. In my controller I can call the recaptcha_check_answer method and get back valid responses. I have all of the files installed and configured correctly as I can use the methods from the recaptcha class and get back good responses.
My issue is that I would like to have an invalid reCaptcha trigger a CI form_validation error but I have spent alot of time on this and cannot get it to trigger. I am pretty new to CI so pardon my ignorance if this is something easy.
I have tried to throw a form_validation error when the is_valid response comes back NULL. If NULL then I tried to do the following:
$this->form_validation->set_message('recaptcha_response_field', 'reCaptcha', lang('recaptcha_incorrect_response'));
echo form_error('recaptcha_response_field');
Here is what the reCaptcha API responses look like for Valid and Invalid captcha's:
Valid = stdClass Object ( [0] => is_valid [1] => error [is_valid] => 1 )
Invalid = stdClass Object ( [0] => is_valid [1] => error [is_valid] => [error] => incorrect-captcha-sol )
Here is the code I have in my Controller:
class Contact extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->library('recaptcha');
$this->recaptcha->set_key ('MY_PUBLIC_KEY_HERE' ,'public');
$this->recaptcha->set_key ('MY_PRIVATE_KEY_HERE' ,'private'); // For private key
// Is this a Form Submission?
if (!empty($_POST))
{
// LOAD VALIDATION AND SET RULES
$this->load->library('form_validation');
$this->load->helper('form');
$this->form_validation->set_rules('first_name', 'First Name', 'required');
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('recaptcha_response_field', 'reCaptcha', 'required|recaptcha_check_answer');
$this->_resp = $this->recaptcha->recaptcha_check_answer ( $this->input->ip_address(), $this->input->post('recaptcha_challenge_field',true), $this->input->post('recaptcha_response_field',true));
// If the reCaptcha doesnt match throw an form_valiation Error
if ($this->_resp->is_valid == '')
{
$this->form_validation->set_message('recaptcha_response_field', 'reCaptcha', lang('recaptcha_incorrect_response'));
echo form_error('recaptcha_response_field');
}
if ($this->form_validation->run() !== FALSE)
{
// SUCCESS NO ERRORS - SEND EMAIL DATA AND RETURN TO HOME
$this->load->library('email'); // LOAD EMAIL LIBRARY
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from($this->input->post('email'), $this->input->post('first_name').' '.$this->input->post('last_name'));
$this->email->to('jassen.michaels#gmail.com');
$this->email->cc('');
$this->email->bcc('');
$this->email->subject('Contact Email From Spider Design Website');
$this->email->message(
'First Name: '.$this->input->post('first_name')."\r\n".
'Last Name: '.$this->input->post('last_name')."\r\n".
'Company: '.$this->input->post('company')."\r\n".
'Location: '.$this->input->post('location')."\r\n"."\r\n".
'I am interested in learning: '."\r\n"."\r\n".
'Information Architecture: '.$this->input->post('information_architecture')."\r\n".
'Web Design: '.$this->input->post('web_design')."\r\n".
'Graphic Design: '.$this->input->post('graphic_design')."\r\n".
'Email Marketing: '.$this->input->post('email_marketing')."\r\n".
'Social Media: '.$this->input->post('social_media')."\r\n".
'Content Management: '.$this->input->post('content_management')."\r\n".
'Search Engine Optimization: '.$this->input->post('seo')."\r\n".
'Web Traffic Analytics: '.$this->input->post('wta')."\r\n"."\r\n".
'Preferred Method of Contact: '."\r\n".
'Phone: '.$this->input->post('phone')."\r\n".
'Email: '.$this->input->post('email')."\r\n"."\r\n".
'Comments: '."\r\n".
$this->input->post('comments')
);
//$this->email->send();
//$this->load->helper('url');
//redirect('http://sdi.myspiderdesign.com/fuel');
}
}
// Not a form submission, load view
$this->load->helper('form');
$this->load->view('include/spider_header');
$this->load->view('contact'); // Content Area
$this->load->view('include/spider_footer'); // Footer
}
}
I have commented out the redirects and contact email at the bottom of the form until I can troubleshoot this issue.
Thanks in advance for all your help!
I used the callback_ function within the form_validation library. Setup an additional function inside the controller that made the API call and if the captcha did not pass it would throw a validation_error.

Resources