0

I added some fields in the Magento contact form, but I have a problem with one field, which is a select type.

I try to display the label of the option on the mail but now the value is display....

Can we fix that ? (form.phtml)

<select name="query-select" id="query-select">
   <option disabled>Votre type de demande</option>
   <option value="demande-devis">Une demande de devis</option>
   <option value="delai-livraison">Un délai de livraison</option>
   <option value="retour-marchandise">Une demande de retour de marchandise</option>
   <option value="dispo-produit">La disponibilité des produits</option>
   <option value="ouverture-compte">Une ouverture de compte</option>
   <option value="sav">Une réclamation/SAV</option>
   <option value="suivi">Le suivi de ma commande</option>
   <option value="autre">Autre</option>
</select>

submitted_form.html

{{template config_path="design/email/header_template"}}

<table class="message-details">
    <tr>
        <td><strong>{{trans "Name"}}</strong></td>
        <td>{{var data.name}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Email"}}</strong></td>
        <td>{{var data.email}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Entreprise"}}</strong></td>
        <td>{{var data.company}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Type de demande"}}</strong></td>
        <td>{{var data.query-select}}</td>
    </tr>

</table>
<p><strong>{{trans "Message"}}</strong></p>
<p>{{var data.comment}}</p>

{{template config_path="design/email/footer_template"}}

Thanks !

3

For achieved this functinality

We need to create source model.

Dont used it inline in form

First create source model

    <?php
    namespace Custom\Module\Model\Config\Source;

    use Magento\Framework\Option\ArrayInterface;

    class Contact implements ArrayInterface
    {

        public function toOptionArray()
        {
            $loadedData = array();

            $loadedData[] = [
                        'label' => 'Une demande de devis',
                        'value' => 'demande-devis',
                    ];
            $loadedData[] = [
                        'label' => 'Un délai de livraison',
                        'value' => 'delai-livraison',
                    ];
            $loadedData[] = [
                        'label' => 'Une demande de retour de marchandise',
                        'value' => 'retour-marchandise',
                    ];

            return $loadedData;

        }

    }

Then add form phtml

    <?php      
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $contactOption = $objectManager->create('Custom\Module\Model\Config\Source\Contact')->toOptionArray();
    ?>
    <select name="query-select" id="query-select">
       <option disabled>Votre type de demande</option>
    <?php foreach($contactOption as $contact){ ?>
        <option value='<?php echo $contact['value'] ?>'><?php echo $contact['label']; ?></option>
    <?php }?> 
    </select>

Then update sendemail Function and following code

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $contactOption = $objectManager->create('Custom\Module\Model\Config\Source\Contact')->toOptionArray();

    foreach($contactOption as $contact){

            if(strtolower($contact['value']) == strtolower($post['query-select'])){

                $post['query-select'] = $contact['label'];
            }

    }
 ?>
  • I try to understand but I don't know in which files I need to put this code ? I found for the first and the second but not for the last to update the sendmail function. – Robert S. Aug 12 at 14:07
  • In controller file if used default magento please override it. Magento\Contact\Controller\Index\Post Please check this file path. – Vijay Khirade Aug 13 at 5:12
  • Yeah, it's works ! And if I want to send the form contact on different mail address according to the condition of the select value, is it possible ? – Robert S. Aug 13 at 8:27
  • Yes it is possible.but with our custom code. Can you please mark as correct answer it will help other developer too. – Vijay Khirade Aug 13 at 8:42
  • Ok :) Which file I need to update ? – Robert S. Aug 13 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.