We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54524
    • 34 Posts
    Hi,
    I created a form with Formit but I can't figure out how to send the values to my email.
    The basic fields like name and email work fine, it is hard because i'm using Migx and the selection of numbers.
    I would like to have an overview of the products with their value(number) in the mail like:
    Product 1 (title): chosen number
    Product 2 (title): chosen number
    Product 3 (title): chosen number etc...

    The Chunk for the products looks like this:
    <li>
    <p>
    [[+title]]
    </p>
    
    <select name="[[+title]]" id="[[+title]]" value="[[[[+title]]]]">
                <option value="0"[[!+fi.numbers:FormItIsSelected=`0`]]>0</option>
                <option value="1x" [[!+fi.numbers:FormItIsSelected=`1`]]>1</option>
                <option value="2x" [[!+fi.numbers:FormItIsSelected=`2`]]>2</option>
                <option value="3x" [[!+fi.numbers:FormItIsSelected=`3`]]>3</option>
    			<option value="4x"[[!+fi.numbers:FormItIsSelected=`4`]]>4</option>
                <option value="5x" [[!+fi.numbers:FormItIsSelected=`5`]]>5</option>
                <option value="6x" [[!+fi.numbers:FormItIsSelected=`6`]]>6</option>
                <option value="7x" [[!+fi.numbers:FormItIsSelected=`7`]]>7</option>
    			<option value="8x" [[!+fi.numbers:FormItIsSelected=`8`]]>8</option>
                <option value="9x" [[!+fi.numbers:FormItIsSelected=`9`]]>9</option>
                <option value="10x" [[!+fi.numbers:FormItIsSelected=`10`]]>10</option>
            </select>
    </li>


    The formit call looks like this:
    [[!FormIt?
    &validate=`[[!getImageList? &tvname=`Bestellijst` &tpl=`tLoadlist` &outputSeparator=`,`]]`
    &hooks=`spam,email,FormItSaveForm`
    &emailTpl=`OrderReport`
    &emailSubject=`Contactformulier vanuit [[++site_name]]`
    &emailTo=`mymailadress`
    &validationErrorMessage=`Niet alle velden zijn gevuld`
    &successMessage=`<div class="message">Bedankt voor uw bericht</div>`
    &validate=`	naam:required,
    email:email:required,
    inputChecker:blank`
    &spamEmailFields=`email,naam`
    ]]


    Already tried so many things in the the emailTpl, but nothing seems to work.
    Usually the field I created for the products with values keeps empty.

    Appreciate it so much if someone can help me.
    Would be perfect if only the products higher then zero will be shown.

    Thanks a lot!
      • 46886
      • 1,154 Posts
      I've wavered about whether to reply, I don't want to send you the wrong way. I have good days and bad, but let's get you going anyway.

      I've looked at your code which mostly looks fine, but your chunk is a little weird.

      Why do you have [[+title]] outputted in the form, before you get to the checkboxes, which define the field value of [[[[+title]]]] in the database? It seems to me those checkboxes probably shouldn't be defining a field called 'title', but rather perhaps a field called say [[[[+option_quantity]]]]

      Here is the page with some examples in formit, I am not a formit user so my advice is limited. I found the 'Handling Required on Checkboxes' section to be useful for you, let me explain below.

      https://docs.modx.com/extras/revo/formit/formit.tutorials-and-examples/formit.handling-selects,-checkboxes-and-radios


      Usually the field I created for the products with values keeps empty.

      As I said I do not have a lot of confidence in my analysis, but, you do say the checkbox isn't saving anyway, let's get the data saved first. If the checkbox data is getting saved then it can output.

      Update I found this in the docs, the problem we have here is to get your form saved, so you will need to remove the other hooks first, to see if we can get past the form saving.

      Hooks are basically scripts that run after a form is validated by FormIt. They can be chained; the first hook will execute, and if succeeds, will proceed onto the next hook. If a hook fails, it will not proceed to the next hook, but return back to the form with any error messages sent.
      [ed. note: nuan88 last edited this post 5 years, 8 months ago.]
        • 54524
        • 34 Posts
        Thanks for the response!
        It might be good to know that the form get saved correctly. When I go to Formit (hook: FormItSaveForm) I can see all the forms with the entered values. And when I do not use any &emailTpl then the same information will be in my mailbox. Then I see all the products with their values. But ofcourse I want to create a nice template for the information.

        [[+title]] is outputted in the form before, because the title is created in Migx and needs to be shown in the form on the website. It's only to show on the website. I also set is as select value because the title and value needs to connect.

        I have seen the link you send many times, but it is not very clear for me how the code exactly needs to look like.
        And this information is even more unclear for me: https://docs.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers)

        I probably miss some logic thinking in these.

          • 46886
          • 1,154 Posts
          I know, they are hard. Well, let's get you closer and someone with more knowledge will stop by soon enough.

          Ok so I really feel that you cannot make title the checkbox value (that's in the db) if you already have title from MIGX, that's like trying to re-write the value, it seems unwise to me. Its also not descriptive which will make it harder, title really means as I said something like 'selected_quantity'. The danger here is that later you will have to remember that 'title' really means something quite different, if you forget the connection will be lost and it will be a pain. Trust me on this all my code ends up like this lol.

          Still, if you can see the values on the backend then they are being saved. Also you said both that 'you' correctly get the info if there is no tpl, and that's what you want right, for you to get it? The performance is fine except for the form styling in the email?

          Please let me know if I make any mistake in talking about both what is happening now and what you want to happen. Sometimes users come in talking about the code, but its important to keep sight of what the goal is. Its possible to realize we are working on the wrong problem halfway through, I don't necessarily understand your true goals, so keep reminding us if we get it wrong.

          Now, if it was me I would be looking for that default tpl email that you receive when no tpl is specified, its got to be in there, probably in the normal Formit chunks. That one gives you the right output, and you can then edit it with the styling you want.

          Previously I was going to say you might need two snippets, one to save the data and one to push out the email. But the quote I posted said that those hooks are all after the form has been processed.

          Finally given the provblem with [[+title]] its possible that in Modx memory the value is coming from MIGX in other words isn't being saved into Modx memory (because MIGX is still reporting the previous value). IDK though that's speculation on my part.
            • 17301
            • 932 Posts
            Can you post your emailTpl chunk please.
              ■ email: [email protected] | ■ website: https://alienbuild.uk

              The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
              • 17301
              • 932 Posts
              Off the bat though I can see you're setting the value of numbers depending on what option is selected but your select value has a value of title, not numbers. You also have extra brackets around your value.
                ■ email: [email protected] | ■ website: https://alienbuild.uk

                The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                • 46886
                • 1,154 Posts
                Nice to see you LK

                Here is a bit of code from the docs, I edited it a bit, could this be useful to fix the problem? Its a bit different though

                <label>Quantity: [[!+fi.error.quantity]]</label>
                <input type="checkbox" name="quantity[]" value="1" [[!+fi.color:FormItIsChecked=`1`]] > 1 
                <input type="checkbox" name="quantity[]" value="2" [[!+fi.color:FormItIsChecked=`2`]] > 2 
                <input type="checkbox" name="quantity[]" value="3" [[!+fi.color:FormItIsChecked=`3`]] > 3
                  • 54524
                  • 34 Posts
                  Thanks again. I understand that it is not easy to do it like this with the Title but I need my client to fill in and change the list of items when necessarily.

                  Yeah indeed the first part 'The chunck with products' seems to work. Without template I get this in the mail:
                  It is close form what I want, so I should be able to create this fields by myself.

                  Panini_Caprese: 2x
                  Panini_Hawaï: 0
                  Panini_Fumé: 0


                  The emailTpl that this creates looks like this, I can not do anything whit it.
                  <p>[[+fields]]</p>


                  I think we might be too much focussing on the first part, which I think is fine for now because it works.
                  My problem is that I have no idea how to get the field in the email template.

                  I already tried so many things for the chuncks. For example I have this in the emailTpl (as you can see I really have no idea)(first I was using numbers as select value):

                  [[+title]]:[[+numbers:FormItIsSelected]]


                  [[+[[+title]]:notempty=`
                  <li>[[+title]]:[[+[[+title]]]]</li>
                  `]]


                  <ul>[[getImageList? &tvname=`Bestellijst` ]]
                  [[+numbers[[+MIGX_id]]:notempty=`
                  <li>[[+title]]:[[+numbers:FormItIsSelected[[+MIGX_id]]]]</li>
                  `]]
                  </ul>


                  I need the select options, not checkboxes like the code above.

                  Hopefully you understand a little bit more what I am doing.
                  Otherwise let me know smiley

                    • 46886
                    • 1,154 Posts
                    Yeah you are all over the place, its ok all part of learning. Its not easy I know!

                    With coding we have to build it step by step, a later step may be affected by an earlier error

                    Ok I need to make sure where you are:

                    1. with no tpl in the code

                    you get an email, with some of the right info in it that you want.

                    2. with a tpl specified in the code

                    you get an email, but with no info in it.

                    Am I right?

                    The email you get with no tpl specified is still using a tpl, its the default tpl.

                    It seems to be finding your fields, if its got the right output then just put all of them in your form

                    Just find that tpl and you can modify it with your html

                      • 54524
                      • 34 Posts
                      That's correct I tried to say that above, that the default tpl contains this:
                      <p>[[+fields]]</p>


                      But I can't do anything whit this because I want the fields separated.

                      What a little strange is: when I copy the code above in my own tpl, it doesn't always process it, when I've exactly the same code in the tpl, I get this code seen in the email: [[+fields]]. Why is that? Why is there a difference?

                      Another example: when I type:
                      [[+title]]:[[!FormItIsSelected?]]

                      I get in the email:
                      [[+title]]: selected="selected"


                      It just isn't doing anything.