Jump to content

Creating new contact form from prestashop contact-form.tpl


manuwow

Recommended Posts

Hi!

 

I'm using Prestashop 1.6.5 version and I have to create a new contact form. I duplicate contact-form.tpl and his ContactController.php

 

The problems is when I submit the form, because it try to call to ContactController instead of myformController.php

 

Then I change the name and ID from the submit button.

 

Have I to change the form action url? What I have to do?

 

Thanks a lot!

 

 

contact-form-mayorista.tpl

<form action="{$request_uri|escape:'html':'UTF-8'}" method="post" class="contact-form-box" enctype="multipart/form-data">
		<fieldset>
            <h3 class="page-subheading">Registrate</h3>
            <div class="row">
                <div class="col-xs-12 col-md-3">
                    <div class="form-group selector1">
                                    
                                    <label for="name">Nombre y apellidos</label>
					
									<input class="form-control grey" type="text" id="name" required name="name"/>

                                   
                                    <label for="dni">DNI/CIF</label>
                    
                                    <input class="form-control grey" type="text" id="dni" required name="dni"/>
                                     
                                    
                                    <label for="shopname">Nombre de la Tienda</label>
                    
                                    <input class="form-control grey" type="text" id="shopname" required name="shopname"/>


                                    <label for="direccion">Dirección Fiscal</label>
                    
                                    <input class="form-control grey" type="text" id="direccion" required name="direccion"/>


                                    <label for="localidad">Localidad</label>
                    
                                    <input class="form-control grey" type="text" id="localidad" required name="localidad"/>


                                    <label for="cp">Código Postal</label>
                    
                                    <input class="form-control grey" type="text" id="cp" required name="cp"/>

                                    
                                    <label for="provincia">Provincia</label>

                                    <select class="form-control grey" id="provincia" required name="provincia">
                                     <option>-- Seleccionar --</option>
                                     <option value='alava'>Álava</option>
                                     <option value='albacete'>Albacete</option>
                                     <option value='alicante'>Alicante/Alacant</option>
                                     <option value='almeria'>Almería</option>
                                     <option value='asturias'>Asturias</option>
                                     <option value='avila'>Ávila</option>
                                     <option value='badajoz'>Badajoz</option>
                                     <option value='barcelona'>Barcelona</option>
                                     <option value='burgos'>Burgos</option>
                                     <option value='caceres'>Cáceres</option>
                                     <option value='cadiz'>Cádiz</option>
                                     <option value='cantabria'>Cantabria</option>
                                     <option value='castellon'>Castellón/Castelló</option>
                                     <option value='ceuta'>Ceuta</option>
                                     <option value='ciudadreal'>Ciudad Real</option>
                                     <option value='cordoba'>Córdoba</option>
                                     <option value='cuenca'>Cuenca</option>
                                     <option value='girona'>Girona</option>
                                     <option value='laspalmas'>Las Palmas</option>
                                     <option value='granada'>Granada</option>
                                     <option value='guadalajara'>Guadalajara</option>
                                     <option value='guipuzcoa'>Guipúzcoa</option>
                                     <option value='huelva'>Huelva</option>
                                     <option value='huesca'>Huesca</option>
                                     <option value='illesbalears'>Illes Balears</option>
                                     <option value='jaen'>Jaén</option>
                                     <option value='acoruña'>A Coruña</option>
                                     <option value='larioja'>La Rioja</option>
                                     <option value='leon'>León</option>
                                     <option value='lleida'>Lleida</option>
                                     <option value='lugo'>Lugo</option>
                                     <option value='madrid'>Madrid</option>
                                     <option value='malaga'>Málaga</option>
                                     <option value='melilla'>Melilla</option>
                                     <option value='murcia'>Murcia</option>
                                     <option value='navarra'>Navarra</option>
                                     <option value='ourense'>Ourense</option>
                                     <option value='palencia'>Palencia</option>
                                     <option value='pontevedra'>Pontevedra</option>
                                     <option value='salamanca'>Salamanca</option>
                                     <option value='segovia'>Segovia</option>
                                     <option value='sevilla'>Sevilla</option>
                                     <option value='soria'>Soria</option>
                                     <option value='tarragona'>Tarragona</option>
                                     <option value='santacruztenerife'>Santa Cruz de Tenerife</option>
                                     <option value='teruel'>Teruel</option>
                                     <option value='toledo'>Toledo</option>
                                     <option value='valencia'>Valencia/Valéncia</option>
                                     <option value='valladolid'>Valladolid</option>
                                     <option value='vizcaya'>Vizcaya</option>
                                     <option value='zamora'>Zamora</option>
                                     <option value='zaragoza'>Zaragoza</option>
                                    </select>

                                    							
                    
                                    <label for="email">Email</label>
                                    {if isset($customerThread.email)}
                                        <input class="form-control grey" type="text" id="email" name="from" value="{$customerThread.email|escape:'html':'UTF-8'}" readonly="readonly" />
                                    {else}
                                        <input class="form-control grey validate" type="text" id="email" name="from" data-validate="isEmail" value="{$email|escape:'html':'UTF-8'}" />
                                    {/if}
                              
                                
                                <label for="phone">Teléfono</label>
                                
                                <input class="form-control grey" type="text" id="phone" required name="phone"/>

                                <label for="pass">Contraseña</label>
                                
                                <input class="form-control grey" type="password" id="pass" required name="pass"/>
                                   
                                {if $fileupload == 1}
                                    <p class="form-group">
                                        <label for="fileUpload">Adjunte su modelo 038</label>
            			                <input type="hidden" name="MAX_FILE_SIZE" value="{if isset($max_upload_size) && $max_upload_size}{$max_upload_size|intval}{else}3000000{/if}" />
                                        <input type="file" name="fileUpload" id="fileUpload" class="form-control" />
                                    </p>
                                {/if}
                                
                            
                           <button type="submit" name="submitMayorista" id="submitMayorista" class="button btn btn-default button-medium"><span>Registrar <i class="icon-chevron-right right"></i> </span></button>
            </div></div>
           
        </fieldset>
    </form>

ContactMayoristaController.php

class ContactMayoristaControllerCore extends FrontController
{
    public $php_self = 'zona-mayorista';




    /**
    * Start forms process
    * @see FrontController::postProcess()
    */
    public function postProcess()
    {
        if (isset($_POST['submitMayorista']) {
            $extension = array('.doc', '.docx', '.pdf','.png', '.jpeg', '.gif', '.jpg');
            $file_attachment = Tools::fileAttachment('fileUpload');
            $name = Tools::getValue('name');
            $dni = Tools::getValue('dni');
            $shopname = Tools::getValue('shopname');
            $direccion = Tools::getValue('direccion');
            $localidad = Tools::getValue('localidad');
            $cp = Tools::getValue('cp');
            $provincia = Tools::getValue('provincia');
            $phone = Tools::getValue('phone');
            $pass = Tools::getValue('pass');
         
            $msg = $name;
            $msg.= $dni;
            $msg.= $shopname;
            $msg.= $direccion;
            $msg.= $localidad;
            $msg.= $cp;
            $msg.= $provincia;
            $msg.= $phone;
            $msg.= $pass;


            mail('[email protected]','Registro Mayorista',$msg)

    }
}
    public function setMedia()
    {
        parent::setMedia();
       
     
    }

    /**
    * Assign template vars related to page content
    * @see FrontController::initContent()
    */
    public function initContent()
    {
        parent::initContent();

        
        $this->setTemplate(_PS_THEME_DIR_.'contact-form-mayorista.tpl');
    }

    

  
}
Link to comment
Share on other sites

I would not go this way. Instead, I would write an override for the ContactController.php and add new fields there as they are needed.

Why?

As long as the contact-form.tpl does not contain this new fields, nothing special happens. So you can easily handle as many news fields in the existing controller and have as many new contact-forms as you like.

 

In this post

 

https://www.prestashop.com/forums/topic/618098-contact-form-subject-heading/

 

#5 I uploaded the complete code of a new contact controller with new fields (customer name, automatically set if user is logged in and customer phone).

Have a look there.

 

IMPORTANT:

Field names in the tpl and the controller must match. Add id as well as name in the tpl file. Example one field in the the tpl:

<p class="form-group">
     <label for="custname">Vor- / Nachname</label>
     <input class="form-control grey" type="text" id="custname" name="custname" value="Hans Tester (13)" />
</p>
Edited by Scully (see edit history)
Link to comment
Share on other sites

Hi Scully, thanks for your reply.

 

I'm going to try this, but I have a question, to do a override have I to put the new ContactController.php in Override directory or I have to overwrite the existing controller?

 

This action would concern to my default contact form?

 

Thanks in advance!!

Edited by manuwow (see edit history)
Link to comment
Share on other sites

You put a new file here:

/override/controllers/front

The path must be idential to its original location but under the /override directory.

 

After you did this, you have to delete the file ./cache/class_index.php. This file will be regenerated automatically.

If you don't delete it, your new override would have no effect.

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...