I am running an Ajax tutorial example and a line gives error in controller file. What I'm doing is if a field is blank and user blurs out of it an error will display below the field.
Here is the whole function in MessagesController.php
public function validate_form()
{
if($this->RequestHandler->isAjax())
{
$this->request->data['Message'][$this->request->params['form']['field']] = $this->request->params['form']['value'];
$this->Message->set($this->request->data);
if($this->Message->validates())
{
$this->autoRender = FALSE;
}
else
{
$error = $this->validateErrors($this->Message);
$this->set('error', $error[$this->request->params['form']['field']]);
}
}
}
The error line is this:
$this->request->data['Message'][$this->request->params['form']['field']] = $this->request->params['form']['value'];
And error is this
Undefined index: form [APP\Controller\MessagesController.php, line 30]
Actually the tutorial was based on previous version of Cake but I have made proper changes compatible with current version but still error shows. Can someone please tell me what might be wrong in this line or elsewhere in the code. Thanks a lot.
$this->request->params does not contain a form index.
I think you should be looking at your $this->request->data?
$this->request->params has only information about your request: the action, the controller, any named parameters and so on.
The error you get is actually normal.
Add comment with link to tutorial.
Related
I have a website and it has a member registry (Way of Life). It uses phpmailer which I am not very familiar with. When you enter data and click register, it returns this:
Fatal error: Call to undefined method Mail::setMessageType() in
/home/u536535282/public_html/classes/phpmailer/phpmailer.php on line
989
The lines that this is referring to are shown below:
$this->error_count = 0; // reset errors
$this->setMessageType();
if (!$this->AllowEmpty and empty($this->Body)) {
throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
}
If someone colud tell me what i need to change, I would appreciate it, as it would get my site going again
I am starting to learn Yii framework. In the tutorial video i copied the code where were using setFlash for error messages on a form. I have inspected the code a lot of times and im pretty sure its identical to the video however i keep getting an error message that is referring to this line:
Yii:app()->user->setFlash('failure', "There was a problem saving the data!");
The error says:
Fatal error: Label 'Yii' already defined in C:\wamp\www\photogallery\protected\controllers\AlbumController.php on line 77
public function actionCreate()
{
$model=new Album;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Album']))
{
$model->attributes=$_POST['Album'];
if($model->save()){
Yii:app()->user->setFlash('saved', "Data saved!");
$this->redirect(array('update','id'=>$model->id));
} else{
Yii:app()->user->setFlash('failure', "There was a problem saving the data!");
}
}
$this->render('create',array(
'model'=>$model,
));
}
Maybe its a typo im missing but its exactly the same as the video tutorial and it seems to work for him and i took a look at some other similar code online and it seemed to use 2 instances of Yii:app() in an if/else statement. The error message didnt return any similar issues on google so im guessing its something simple
You need to use a double colon, not single, when using the static method.
Yii::app() not Yii:app()
I'm Not too sure on what this error is, from looking around, it must be something to do with the database declarations. I'm trying to make a drop down box on my Widget, by selecting different fields of the database, different masks will be selected and will allow for different widgets to be made on later pages.
The part of my code where i think the error is, is:
$this->build("p4a_db_source", "login")
->setTable("meetingrooms")
->addJoin("login.meetingrooms",
"login.meetingrooms.MeetingRoom = login.meetingrooms.MeetingRoom",
array('position'=>'Ident'))
->addOrder("position")
->load();
$this->setSource($this->login);
$this->firstRow();
$this->build('p4a_field','location')
->setSource('login')
->setLabel('location')
->setValue('Please Select...')
->setType('select')
->setWidth(60);
$this->weight->label->setWidth(60);
I know its a similar question to my previous one, but its a different code entirely, but this one should be much easier to fix.
Thanks for the help.
The Stacktrace (Fatal error: Call to a member function getPk() on a non-object in C:\xampp\htdocs\p4a\p4a\objects\widgets\field.php on line 468) isn't indicating the line at which the error is occurring so i'm unsure where exactly the problem is originating from,
The rest of the code (including previous) is:
class main_dashboard_mask extends P4A_Base_Mask
{
public function __construct()
{
parent::__construct();
$this->setTitle("Dashboard");
$this->build('p4a_field','MeetingRooms');
$this->MeetingRooms->setLabel("This is the meeting room label");
$this->build('p4a_button', 'continue')
->setLabel('Continue?')
->implement("onclick", $this, "change");
$this->build('p4a_field','booking')
->setlabel('Viewing?')
->setType('checkbox')
->setValue(true);
$this->booking->label->setTooltip('If you are booking a meeting room, check this box');
$this->build("p4a_db_source", "login")
->setTable("meetingrooms")
->addJoin("login.meetingrooms",
"login.meetingrooms.MeetingRoom = login.meetingrooms.MeetingRoom",
array('position'=>'Ident'))
->addOrder("position")
->load();
$this->setSource($this->login);
$this->firstRow();
$this->build('p4a_field','location')
->setSource('login')
->setLabel('location')
->setValue('Please Select...')
->setType('select')
->setWidth(60);
$this->weight->label->setWidth(60);
$this->Meetingrooms();
}
private function Meetingrooms()
{
$this->build('P4A_fieldset', 'widgetframe')
->anchor($this->location)
->anchorLeft($this->booking)
->anchorLeft($this->continue)
->setLabel('Meeting Room Bookings');
}
}
I think you are not getting the object. That is why it's giving error of non-object.
Just print the object on which you are calling the method getPk(). If it is valid object then
only call that method.
i got it, sorry i was looking in the right place but didn't see where i was wrong...
where before the code was ->
$this->setSource($this->login);
$this->firstRow();
$this->build('p4a_field','location')
->setSource('login') // <- this is the error(the Pk variable hasn't been set here)
->setLabel('location')
->setValue('Please Select...')
->setType('select')
->setWidth(60);
$this->weight->label->setWidth(60);
$this->Meetingrooms();
the fix is ->
->setSource($this->login)
Thanks for the assistance =]
Do you have a full stacktrace ? What line of code exactly generates this error ?
Anyway, you have to locate the code where $object->getPk() is called. The error means that you're trying to use a function ->getPk() on an $object that is null ..
I am trying to add a function named "addNotification" to my page "functions.php"
My function:
function addNoti($text,$userid)
{
mysql_query("INSERT INTO notifications (time,text,userid) VALUES('".time()."','$text','$userid')");
if(mysql_affected_rows() != 1)
return 2;
else
return 100;
}
A couple of hundreds line BELOW that^ (same page), I have my registration function "register":
function doRegister()
{
global $datesetting;
mysql_query("query to register goes here");
addNoti("You just joined us!","$userid");
}
Although, whenever I process my registration form, I get the following error:
Fatal error: Call to undefined function addNoti() in /home/domain/public_html/path/to/functions.php on line 278
(Line 278 is where the addNoti is called)
Whenever I try to move addNoti to another page, and load that page in functions.php I get no error.
Please help.
Thank you in advance.
Keep in mind that in PHP you can declare function in conditional block. It could be that in your code execution took the other branch and never got to the function definition. Check the code blocks, check if the code with the function definition gets executed (echo or var_dump are your friends)
Is it a typo? In your question you name the function addNotification and addNoti()...
Do you call doRegister() before addNoti() occurred in your script?! That is the question!
From the two functions only it is hard to say what the problem can be. Did you accidently put the function addNoti inside another function (before the closing bracket)?
I am getting the following error:
Fatal error: Call to a member function error() on a non-object in /home/gamepla3/public_html/football/result.php on line 177
The line for this is
<?php echo $form->error("homescore"); ?>
I'm failing to see how this could be the case?
The thing worked fine before I added working code into my html document so it looked better.
Now I can't get it working??
EDIT.
When the code is not within HTML, it works fine.
Once I have it within the HTML, it throws back an error?
Has anyone seen anything like this before?
var_dump($form);
Well, this just require a little & simple debug logic
Confirm $form is a Form object, try this
$class_methods = get_class_methods('form');
foreach ($class_methods as $method_name)
{
echo "$method_name\n";
}
does error is a defined method for Form object?
Based on your comment, the error is not a define method for object Form, so
$form->setError('homescore');
$errors = $form->getErrorArray();
// or $errors = $form->getError();