0

ERROR:

  Fatal error: Call to a member function setGuestName() on a non-object in IndexController.php
  {main}( ) - index.php
  Mage::run( ) - index.php(line:87)
  Mage_Core_Model_App->run( ) - Mage.php(line:684)
  Mage_Core_Controller_Varien_Front->dispatch( ) - App.php(line:354)
  Mage_Core_Controller_Varien_Router_Standard->match( ) - Front.php(line:172)
  Mage_Core_Controller_Varien_Action->dispatch( ) - Standard.php(line:250)
  Test_Contacts_IndexController->postAction( ) - Action.php(line:418)

My code:

  $model = Mage::getModel('contacts/contacts');
  $model->setGuestName( trim($post['name']) );
  $model->setGuestEmail(trim($post['email']));
  $model->setGuestTelephone(trim($post['telephone']));
  $model->setGuestComments(trim($post['comment']));
  $model->setGuestAttachment(trim($post['attachment']));
  $model->save( );   
Shaunak Shukla
  • 2,347
  • 2
  • 18
  • 29

3 Answers3

1

I'm not sure how your framework works, but shouldn't it be $_POST[''] instead of $POST['']?

Mostafa Mohsen
  • 766
  • 5
  • 15
0

Is it possible the permissions are incorrectly set on contacts/contacts? Are you sure contacts/contacts is the right location?

Dale
  • 319
  • 2
  • 8
0

Please confirm your model object loading correctly by using following code:

$model = Mage::getModel('contacts/contacts');
echo get_class($model);  
die; 

This will print you model class name If it is loading correctly. Otherwise you need to check config xml.

If you want to save contact form data in database. Here it is teh nice extension: http://www.magentocommerce.com/magento-connect/ultimate-contact-us-page-1.html

Hope this help !!

Pankaj Pareek
  • 3,806
  • 2
  • 31
  • 42
  • I put the above code it not display anything. My config.xml code Test_Contacts_Model Contacts_mysql4 Test_Contacts_Model_Mysql4 contact_details
    – user3608270 Nov 17 '14 at 08:32
  • you resource model name `Contacts_mysql4` and tag name is not matching ``. Also Please make sure your model name will be `Test_Contacts_Model_Contacts` – Pankaj Pareek Nov 17 '14 at 08:39
  • My local directory is like this: Test->Contacts->Model->Mysql4(folder),Contacts.php. Inside of the Mysql4 folder->Contacts(folder),Contacts.php. Inside of the Contacts folder->Collection.php.. Is it correct?? – user3608270 Nov 17 '14 at 09:13
  • Yes. Change `Contacts_mysql4` tag to `contacts_mysql4` in config.xml – Pankaj Pareek Nov 17 '14 at 09:23
  • ya i changed but no changes in output. – user3608270 Nov 17 '14 at 09:33
  • then You need to debug line by line. turn on magento error. http://stackoverflow.com/questions/17143406/how-to-turn-on-magento-error-messages/17143618#17143618 – Pankaj Pareek Nov 17 '14 at 09:45
  • Nw it displaying like Unable to submit your request. Please, try again later Once i click the submit button – user3608270 Nov 17 '14 at 09:53