Jump to content

Calling PHP function from TPL


Recommended Posts

 

 

 

Hi there, 

I'm developing a module to retrieve users and send them an email from admin panel. I can execute the DB query to list the users and pick one. Below that I added a button to perform the action to send the email. But how should I call the php function from module's TPL file ?

// customsignup.php

public function displayForm()
  {
      // Get default language
      $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
  
      // Requete MYSQL

      $rq ='select * from `'._DB_PREFIX_.'customer` where `id_default_group` = 4';
      $selector ='<select id="select_saved_query">
          <option value="" >'.$this->l('Select client').'</option>';
      $result = Db::getInstance()->ExecuteS($rq);
      
      foreach ($result as $query){
          $selector .= '<option value="'.$query['firstname'].'">'.$query['firstname'].' '.$query['lastname']. ' - '.$query['company']. '</option>';
      }

      $this->context->smarty->assign(
        array(
  
            'my_module_name' => Configuration::get('CUSTOM_SIGNUP'),
            'customers' => $result
        )
      );

    return $this->display(__FILE__, 'mycustomsignup.tpl');

 

// views/templates/admin/mycustomsignup.tpl

<select id="client_select">
<option> -- Select client </option>
{foreach $customers as $customer}
    <option value = {$customer.id_customer}>
        {$customer.firstname} {$customer.lastname}  -  {$customer.company} 
    </option>
{/foreach}
</select>
<br>
<button id="show_client_btn" type="button" class="btn btn-default" > Send Email </button>

 

How can I link the button to a specific action in php ?

 

Thanks 

 

Prestashop 1.7.3.1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...