Jump to content

[Solved] Link to contact form subjects


SandraNanou

Recommended Posts

Hi,

I'd like to add a link to the contact form page with the subject pre selected in the select form.

For example, I have 3 different subjects in my contact form :

1- Webmaster

2-Customer service

3-Ask for a quote

I'd like to add a link to the contact form with "2-Customer service" selected.

Something like

http://my-site.com/index.php?controller=contact#id_contact=2

How could I do this?

Thank you!!

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

For those who are interested, here is the solution :

Page product (or other) with the link : 

<a class="btn btn-block btn-secondary" href="{$link->getPageLink('contact', true)|escape:'html':'UTF-8'}?id=3" title="{l s='Ask for a quote' d='Shop.Theme.Catalog'}">{l s='Ask for a quote' d='Shop.Theme.Catalog'}</a>

Contactform.tpl - add ID to options :

<select name="id_contact" id="id_contact" class="form-control form-control-select" onchange="showElemFromSelect('id_contact', 'desc_contact')">
              {foreach from=$contact.contacts item=contact_elt}
                <option id="{$contact_elt.id_contact}" value="{$contact_elt.id_contact}">{$contact_elt.name}</option>
              {/foreach}
            </select>

Custom.js :

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var optionId = getParameterByName('id');

$('#id_contact option#' + optionId).attr("selected","selected");}

Regards

Link to comment
Share on other sites

  • 2 years later...

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