SMAM (short for Send Me A Mail) is a free (as in freedom) contact form embedding software.

form.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. function generateForm(id) {
  2. var el = document.getElementById(id);
  3. var input = {
  4. name: getField('form_name', 'Your name', false), // TODO: configurable prefix
  5. addr: getField('form_addr', 'Your e-mail address', true),
  6. subj: getField('form_subj', 'Your mail\'s subject', false),
  7. text: {}
  8. };
  9. // Adding nodes to document
  10. el.appendChild(input.name);
  11. el.appendChild(input.addr);
  12. el.appendChild(input.subj);
  13. }
  14. // Returns a form field
  15. // id: field HTML identifier
  16. // placeholder: placeholder text
  17. // email: boolean: is it an email field?
  18. // return: a div node containing a label and an input text field
  19. function getField(id, placeholder, email) {
  20. var field = document.createElement('div');
  21. field.setAttribute('id', id); // TODO: configurable prefix
  22. field.appendChild(getLabel(id, placeholder));
  23. field.appendChild(getInputField(id, placeholder, email));
  24. return field;
  25. }
  26. // Returns a label
  27. // id: field HTML identifier
  28. // content: label's inner content
  29. // return: a label node the field's description
  30. function getLabel(id, content) {
  31. var label = document.createElement('label');
  32. label.setAttribute('for', id + '_input');
  33. label.innerHTML = content;
  34. return label;
  35. }
  36. // Returns an input text field
  37. // id: field HTML identifier
  38. // placeholder: placeholder text, field description
  39. // email: boolean: is it an email field?
  40. // return: an input text or email field (depending on "email"'s value') with an
  41. // HTML id and a placeholder text
  42. function getInputField(id, placeholder, email) {
  43. var input = document.createElement('input');
  44. if(email) {
  45. input.setAttribute('type', 'mail');
  46. } else {
  47. input.setAttribute('type', 'text');
  48. }
  49. input.setAttribute('required', 'required');
  50. input.setAttribute('placeholder', placeholder);
  51. input.setAttribute('id', id + '_input');
  52. return input;
  53. }