I have created the module with a form in front end on submit it send email and its working fine, now i also want to save the current form data to a Database table and keep the email functionality too that is working fine right now:
Here is the form action:
<form id="simple_contact_form" name="simple_contact_form" action="<?php echo $this->getUrl('reviews/email/sendemail') ?>" method="post">
And here the function to in my module to send email:
 <?php
 class OptFirst_ReviewMyCompany_EmailController extends
 Mage_Core_Controller_Front_Action
 {
 public function sendemailAction()
 {
 $params = $this->getRequest()->getParams();
 $mail = Mage::getModel('core/email');
 $body = '<p>Hello,</p>
 <p>A New CLient Review Is Received:</p>
 <p><b>Name:</b> ' . ($params['name']) . '<br>
 <p><b>Email:</b> ' . ($params['email']) . '<br>
 <b>Comments:</b> ' . ($params['comment']) . '</p>';
 $mail = new Zend_Mail();
 $mail->setBodyHtml($body);
 $mail->setFrom($params['email'], $params['name']);
 $mail->addTo('[email protected]');
 $mail->setSubject('Review Form');
 try {
 $mail->send();
 Mage::getSingleton('core/session')->addSuccess('Message has been Sent Successfully.');
 $this->_redirect('reviews/');
 }
 catch (exception $ex) {
 Mage::getSingleton('core/session')->addError('Unable to send email. Sample of a custom notification error from Contact Us Form.');
 }
 $connectionresource = Mage::getSingleton('core/resource');
$connectionWrite = $connectionresource->getConnection('core_write');
$table = 'optfirst_contacts';
$query = "insert into ".$table." "
 . "(name,email,comments) values "
 . "(:name, :email, :comments)";
 $binds = array(
 'name' => 'values',
 'email' => 'values',
 'comment' => 'values',
 );
 $connectionWrite->query($query, $binds);
 $this->_redirect('reviews/');
 }
 }
created the query to save data to DB table but it throws an error:
Invalid parameter number: parameter was not defined
What is wrong going on here any help?
- 
 You need to create model and table in database (setup script) after that you can save data from your form like example $params = your post info, $model = Mage::getModel('custom/custom'); $mode->setData($params); $model->save();omelandr– omelandr2016年12月19日 15:53:19 +00:00Commented Dec 19, 2016 at 15:53
- 
 But the form action is currently going to reviews/email/sendemail' so how the form will submited to Database?Xabby– Xabby2016年12月19日 15:55:18 +00:00Commented Dec 19, 2016 at 15:55
- 
 As above - you should add some table via sql script and then save data using model. if in that action you ar lacking of any info you can add some hidden inputs. I there is a provlem where request goes you can change url for form and create custom controller or perform db save in observer on some eventBartosz Kubicki– Bartosz Kubicki2016年12月19日 18:13:23 +00:00Commented Dec 19, 2016 at 18:13
- 
 Any demo work or tutorial will be more helpful @lord_of_stringsXabby– Xabby2016年12月19日 18:32:18 +00:00Commented Dec 19, 2016 at 18:32
- 
 Check how events and observers works - you can find it in google. Also tutorials about creating a table in db and models which serves you for adding data can be easily found. First prepare table, than model and after that you can add saving data in your action. If table you want to save your data to is not custom one and already exists you can use it right now and needs coding only strictly for saving operation.Bartosz Kubicki– Bartosz Kubicki2016年12月20日 08:08:27 +00:00Commented Dec 20, 2016 at 8:08
1 Answer 1
you can send custom email with below code.
 $mail = Mage::getModel('core/email');
 $body = '<p>Hello,</p>
 <p>A New CLient Review Is Received:</p>
 <p><b>Name:</b> ' . ($params['name']) . '<br>
 <p><b>Email:</b> ' . ($params['email']) . '<br>
 <b>Comments:</b> ' . ($params['comment']) . '</p>';
 $mail->setBody($body);
 $mail->setFromEmail($params['email']);
 $mail->setFromName($params['name']);
 $mail->setToEmail('[email protected]');
 $mail->setSubject('Review Form');
 $mail->setType('html');
 try {
 $mail->send();
 Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
 $this->_redirect('');
 }
 catch (Exception $e) {
 Mage::getSingleton('core/session')->addError('Unable to send.');
 $this->_redirect('');
 }
check as a reference
simple way to add in database
 $connectionresource = Mage::getSingleton('core/resource');
 $connectionWrite = $connectionresource->getConnection('core_write');
 $table = 'test';
 $query = "insert into ".$table." "
 . "(test_id,content, abc) values "
 . "(:test_id, :content, :abc)";
 $binds = array(
 'test_id' => 1,
 'content' => 'values',
 'abc' => 'vlues',
 );
 $connectionWrite->query($query, $binds);
for model use this
- 
 Email is already working fine and i have already created this function. Now i want to save this form data to Database too.Xabby– Xabby2016年12月20日 09:05:11 +00:00Commented Dec 20, 2016 at 9:05
- 
 @Xabby did you create model for that table?Qaisar Satti– Qaisar Satti2016年12月20日 09:06:31 +00:00Commented Dec 20, 2016 at 9:06
- 
 Yes I did but i am confused in form action that is already going to another fucntionXabby– Xabby2016年12月20日 09:12:02 +00:00Commented Dec 20, 2016 at 9:12
- 
 @Qasir Satti this is the error Invalid parameter number: parameter was not definedXabby– Xabby2016年12月20日 10:00:20 +00:00Commented Dec 20, 2016 at 10:00
- 
 @Xabby update your question with latest codeQaisar Satti– Qaisar Satti2016年12月20日 10:01:32 +00:00Commented Dec 20, 2016 at 10:01
Explore related questions
See similar questions with these tags.