Home > Net >  How to pass the custom value in contact form 7 message body on WordPress?
How to pass the custom value in contact form 7 message body on WordPress?

Time:11-29

I am trying to display an extra text in drop down menu, in contact form 7 on WordPress.

As I know contact form 7 does not give you this option, so with few lines of jQuery code I find this way, and it works fine.

Every time that user choosing one option from drop down menu with the below code, I display an extra text.

My issue, is that I don't know how to pass the extra text in the message body in order to send via email.

Now when I send an email I am getting the 'first-exam' or 'second-exam' from [type-exam] in message body, but I also want to take in my email the extra text.

Does anyone know how to achieve that, or is there any other solution that contact form 7 gives that option?

Thank you

<div class="form-dropdown">
<label> Your choice
[select type_exam id:choice_exam include_blank "first-exam" "second-exam"]
</label>
</div>
<div id="option1" style="display:none;">first exam extra text...</div>
<div id="option2" style="display:none;">second exam extra text....</div>

<script>
$(document).ready(function () {
  $('#choice_exam').change(function () {
    var val = $(this).val();
    $('#option1').hide();
    $('#option2').hide();
    if (val == 'first-exam') {
      $('#option1').show();
    }
    else if (val == 'second-exam') {
      $('#option2').show();
    }
</script>

Message body

Type exam: [type_exam]

CodePudding user response:

I found a way to solve the above problem. Just use | pipe in the middle of the option value.

<div class="form-dropdown">
<label> Your choice
[select type_exam id:choice_exam include_blank "first-exam | first exam extra text" "second-exam | second exam extra text"]
</label>
</div>

Official doc If you insert a pipe (‘|’) character in the middle of the option value, only the part before the pipe will be open to the outside, and the part after the pipe will be used for mail replacement.

  • Related