Simple Schema Form Success Msg


#1

Hello,

I am currently trying to make a form with simple schema and autoform. I have it almost done. But what doesn’t work are few things…

  1. Recaptcha … - I added a Recaptcha which shows up and can be solved but wether u solve it or not u can always send the form… Only my console tells me if it succeded or not

  2. I can’t figure out how to make a success messange after the contact form sent succesfully…

  3. I wanted to make a custom messange for SimpleSchema.RegEx.Email
    But everytime I try to do it it does not work.

What I tried:

regEx: [
    {exp: SimpleSchema.RegEx.Email, msg: "{{label}} custom messange"},
  ],

It worked with the simpl schema before. Now I get the messange: “email is invalid” instead of my custom messange

Here is my html and js file:

JS:

import './kontakt.html';
import '../../components/main-banner/main-banner.html';
import '../../components/navigationbar/navigationbar.js';
import '../../components/footer/footer.js';
import '../../components/sidebar/sidebar.js';
import '../../components/image-carousel/image-carousel.js';
import SimpleSchema from 'simpl-schema';
import { Email } from 'meteor/email'
SimpleSchema.extendOptions(['autoform']);



Template.App_kontakt.events({
    'submit form': function(e) {
        e.preventDefault();

        var formData = {
            //get the data from your form fields
        };

        //get the captcha data
        var captchaData = grecaptcha.getResponse();

        Meteor.call('formSubmissionMethod', formData, captchaData, function(error, result) {
            // reset the captcha
            grecaptcha.reset();

            if (error) {
                console.log('There was an error: ' + error.reason);
            } else {
                console.log('Success!');
            }
        });
    }
});
SimpleSchema.setDefaultMessages({
  initialLanguage: 'en',
  messages: {
    en: {
	 required: "{{label}} ist erforderlich",
  minString: "{{label}} muss mindestens {{min}}  Zeichen enthalten",
  maxString: "{{label}} darf nicht mehr als {{max}} Zeichen enthalten",
  minNumber: "{{label}} müssen mindestens {{min}}  Nummern enthalten",
  maxNumber: "{{label}} darf nicht mehr als {{max}} Nummern enthalten",
  minDate: "{{label}} must be on or after {{min}} ",
  maxDate: "{{label}} cannot be after {{max}}",
  badDate: "{{label}} is not a valid date",
  minCount: "You must specify at least {{minCount}} values",
  maxCount: "You cannot specify more than {{maxCount}} values",
  noDecimal: "{{label}} must be an integer",
  notAllowed: "{{value}} is not an allowed value",
  expectedString: "{{label}} must be a string",
  expectedNumber: "{{label}} must be a number",
  expectedBoolean: "{{label}} must be a boolean",
  expectedArray: "{{label}} must be an array",
  expectedObject: "{{label}} must be an object",
  expectedConstructor: "{{label}} must be a {{type}}",
  regEx: [
    {msg: "[label] failed regular expression validation"},
    {exp: SimpleSchema.RegEx.Email, msg: "[label] mussst be a valid e-mail address"},
    {exp: SimpleSchema.RegEx.WeakEmail, msg: "[label] mussssst be a valid e-mail address"},
    {exp: SimpleSchema.RegEx.Domain, msg: "[label] must bssse a valid domain"},
    {exp: SimpleSchema.RegEx.WeakDomain, msg: "[label] mussssst be a valid domain"},
    {exp: SimpleSchema.RegEx.IP, msg: "[label] must be a ssvalid IPv4 or IPv6 address"},
    {exp: SimpleSchema.RegEx.IPv4, msg: "[label] must bes a valid IPv6 address"},
    {exp: SimpleSchema.RegEx.Url, msg: "[label] must be sa valid URL"},
    {exp: SimpleSchema.RegEx.Id, msg: "[label] must be a valid alphanumeric ID"}
  ],
      keyNotInSchema: '{{name}} is not allowed by the schema',
    },
  }
});

Schema = {};
Schema.contact = new SimpleSchema({
    name: {
        type: String,
        label: "Name",
        max: 50
    },
    email: {
        type: String,
        regEx: SimpleSchema.RegEx.Email,
        label: "E-mail Adresse"
    },
	phone: {
		type: String,
		regEx: SimpleSchema.RegEx.Phone,
		label: "Telefonnummer"
	},
    message: {
        type: String,
        label: "Nachricht",
        max: 1000
    }
}, { tracker: Tracker });

HTML

................................
          <div id="content">
            <!-- InstanceBeginEditable name="Inhalt" -->
            <h1>Kontakt </h1>
            <div class="formcontainer">
              <p>* Bitte füllen Sie die markierten Felder aus.</p>
              <br>  
  {{#autoForm schema=contactFormSchema id="App_kontakt" type="method" meteormethod="sendEmail"}}
  <fieldset>
    <legend>Contact Us</legend>
    {{> afQuickField name="name"}}
    {{> afQuickField name="email"}}
	{{> afQuickField name="phone"}}
    {{> afQuickField name="message" rows=10}}
	{{> reCAPTCHA}}
    <div>
      <button type="submit" class="btn btn-primary">Submit</button>
      <button type="reset" class="btn btn-default">Reset</button>
    </div>
  </fieldset>
  {{/autoForm}}

              <br>
              <br>
            </div>
.....................................

Can you help me what I did wrong there?


#2

I solved 2by making a hook. Still have 1 and 3