Developer forum

Forum » Templates » Custom contact form as paragraph template

Custom contact form as paragraph template

Jens Mouritzen
Jens Mouritzen
Reply

Does anyone have an idea how to make a custom contact form on a paragraph as a template?
E.g. the customer dont want the "Forms for editors" etc.

How could it be implemented in the below code?

 

<div class="contactform">

      <form action="">

        <label for="fname">First Name</label>

        <input type="text" id="fname" name="firstname" placeholder="Your name..">

        <label for="lname">Last Name</label>

        <input type="text" id="lname" name="lastname" placeholder="Your last name..">

        <label for="country">Country</label>

        <select id="country" name="country">

          <option value="australia">Australia</option>

          <option value="canada">Canada</option>

          <option value="usa">USA</option>

        </select>

        <label for="subject">Subject</label>

        <textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>

        <input type="submit" value="Submit">

      </form>

</div>

Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

I assume that you want to send an email which contains the submitted values?

The most simple solution is to add a mailto action to your form, but it doesn't work that well on all devices.

Another option is to implement your form in a razor template which collects the posted values, creates a System.Net.Mail.MailMessage and sends it using Dynamicweb.Mailing.EmailHandler.Send(message).

Note: "Forms for editors" also has some security features and is able to prevent a lot of spam attacks. You might want to handle that as well if you decide to implement custom forms.

Best regards,
Morten

 
Jens Mouritzen
Jens Mouritzen
Reply

Can you give a small example, with the above HTML code Morten? :)

 
Nicolai Pedersen
Reply

Hi Jens

There is an example of using the emailhandler in the API documentation: https://doc.dynamicweb.com/api/html/79812e7d-6b41-b303-85fc-451aab25723c.htm

That said, you really should not do that... It will be bug fixing forever.

Instead, create a form in forms for editors, and use a custom template to render the form.

BR Nicolai

 

You must be logged in to post in the forum