Jump to content

make a form in smarty and make it submit ?


Recommended Posts

Hi,

In Perstashop I am doing a module. In that module I have view file(smarty template). In smarty I am doing form so that user can submit the form from frontend. Now when user makes fill the form and clicks on submit then the form should save all the vales to thae database. So for that in smarty I made a form like this

 



<div id="content" class="form-wrapper" >
  <div class="form-content">
    <input type="text" id="name" name="name" placeholder="Name" /> <br />
    <input type="text" id="email" name="email" placeholder="email"/> <br />
    <input type="text" id="phone" name="phone" placeholder="Phone Number"/> <br />
    <input type="submit" name="submit-query" id="submit-enquiry" value="submit" />
  </div>
</div>


 

and in the file where the values will be submitted I have made my code like this

 



<?php
include '../../../config/settings.inc.php';
include '../../../config/defines.inc.php';
include '../../../config/config.inc.php';
include(dirname(__FILE__).'/../../../../init.php');


if(Tools::getValue('submit-query')) {
  $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully'));
}
  else {
    $this->_html .= $this->displayError($this->l('You Have Some Errors'));
  }
?>


Now when doing click on my submit button It is showing error like this



Fatal error: Using $this when not in object context in file.php on line 11


Now can someone kindly tell me what is the issue here and how can I make a form in smarty for frontend users so that they can submit the form and the value will be stored to the database. Any help and suggestions will be really appreciable. Thanks

 

Link to comment
Share on other sites

Of course, it depends on your php file. If it's just like that, you won't ever be able to use $this, as it refers to OOP. WHat is that php file supposed to do? Display a smarty template itself?

Then how to submit the form from smarty? Any reference code or any link for this kind of problem?

Link to comment
Share on other sites

The form submission is okay, I don't understand what kind of page you're trying to create though :)

I want something like this there will be a form. When user visits the page and clicks on the button then the form will open in a lightbox. User enters all the fields and make submit form. All the entered data will be stored into the database and if the data stored in the database successfully then user will show a success message in the frontend , all that I want. 

 

So to show the form to user I have taken smarty template for showing form. But from here I don't know how to save the data into database and show message

Link to comment
Share on other sites

I have not used any controller.

 

so where you use this code:

<?php
include '../../../config/settings.inc.php';
include '../../../config/defines.inc.php';
include '../../../config/config.inc.php';
include(dirname(__FILE__).'/../../../../init.php');


if(Tools::getValue('submit-query')) {
  $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully'));
}
  else {
    $this->_html .= $this->displayError($this->l('You Have Some Errors'));
  }
?>

?

Link to comment
Share on other sites

×
×
  • Create New...