top of page

How can my customers print a copy of the contact form they submitted through a Wix website?

Jul 20, 2022
2 min read

Who is our customer and what problem did they want to solve?


Many of our clients have requested a way for their users to store a copy (for their own records) of their submissions via their contact form.



What solution did we provide?


Using the onWixFormSubmitted method for Wix Forms, we were able to capture the fields that were submitted and then display them back on the page (where the "Thank you for submitting" message would normally be) for the customer to view and print.




Check out the code we used below:


$w.onReady(function () {
  $w("#multiStepForm1").onWixFormSubmitted(({ fields }) => {
    // console.log(fields);
    let submissionMessage = `Thank you for submitting! Submitted data is displayed below.<br/> Please print for your records<br/><br/>`;
    const fieldTemplates = buildSubmissionMessage(fields);
    $w("#text24").html = submissionMessage + fieldTemplates;
  });
});

function buildSubmissionMessage(fields) {
  const FIELD_TEMPLATE = `{{fieldName}}: {{fieldValue}}<br/>`;
  const fieldTemplates = fields.reduce((acc, { id, fieldValue, fieldName }) => {
    // console.log(`${fieldName}: value type ${typeof fieldValue}`);

    if (fieldName === "Multi-line Address") {
      const fieldTemplate = `ADDRESS: ${fieldValue.streetAddress}<br/>
			CITY: ${fieldValue.city}<br/>
			STATE: ${fieldValue.region}<br/>
			ZIPCODE: ${fieldValue.zipCode}<br/>`;
      // console.log(fieldTemplate);
      acc.push(fieldTemplate);
    }

    if (id.includes("datePicker")) {
      const fieldTemplate = `${fieldName}: ${fieldValue.toLocaleDateString()}<br/>`;
      // console.log(fieldTemplate);
      acc.push(fieldTemplate);
    }

    if (id.includes("timePicker")) {
      const fieldTemplate = `${fieldName}: ${tConvert(fieldValue)}<br/>`;
      acc.push(fieldTemplate);
      return acc;
    }

    if (id.includes("checkboxGroup") && typeof fieldValue[0] !== "undefined") {
      const fieldTemplate = `${fieldName}: ${fieldValue[0]}<br/>`;
      // console.log(fieldTemplate);
      acc.push(fieldTemplate);
    }

    if (typeof fieldValue === "string") {
      const fieldTemplate = FIELD_TEMPLATE.replace(
        "{{fieldName}}",
        fieldName
      ).replace("{{fieldValue}}", fieldValue);
      // console.log(fieldTemplate);
      acc.push(fieldTemplate);
    }

    return acc;
  }, []);

  return fieldTemplates.join("");
}

function tConvert(time) {
  // Check correct time format and split into components
  time = time.replace(".000", "");
  time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [
    time,
  ];

  if (time.length > 1) {
    // If time format correct
    time = time.slice(1); // Remove full string match value
    time[3] = +time[0] < 12 ? " AM" : " PM"; // Set AM/PM
    time[0] = +time[0] % 12 || 12; // Adjust hours
  }

  return time.join(""); // return adjusted time or original string
}



Have questions about this? Contact us at 225-250-1888 or email robert@roberthebertmedia.com.



About our company


RHM specializes in helping businesses of all sizes and across all industries achieve their digital and web marketing needs. Whether it's designing a new website, building an app, performing custom development, or running Google Ads, our goal is to showcase how you are the best at what you do and help people connect with you. Contact us at 225-250-1888 to get started!








 
 
 

62 Comments


Deborah Rivera
18 hours ago

Adjusting to life back in the States always comes with those little daily rituals that ground you again. For me, it’s been a fun mental reset with this daily 12-Letter Word Puzzle, even if the answer is a bit on the nose. Definitely helps shake off the jet lag brain.

Like

duraisamy1981
3 days ago

Illustrators testing prompts across models may appreciate a side-by-side view of generation services, which makes differences in style control and output quality easier to judge.

Like

Deborah Rivera
5 days ago

Building EV3Rstorm brings back the same joy of trial-and-error engineering you’ll need for the physics chaos in a dear passengers game. Sorting gears here feels like prepping risky cargo; teamwork and patience make both builds land safely. Great LEGO write-up for anyone who likes hands-on problem solving.

Like

Change is easier when you can measure progress. For anyone sharpening reaction speed alongside study or work routines, okiaimx online offers quick browser drills for peek timing, first-shot aim, and crosshair control. Short daily sessions fit busy schedules and make improvement visible.

Like

Mình đọc câu hỏi này mấy lần vì nó rất sát thực tế: khách đã gửi form xong vẫn muốn giữ bản in để đối chiếu, còn chủ trang thì không chắc cách trả file có hợp quy trình không. Bài chỉ dừng ở mức gợi mở nên phần xử lý sau khi in, ai lưu file, dùng giấy gì mình vẫn thấy mơ hồ. Đợt ngồi chờ ở quán cà phê, mình từng nghe vài người bàn chuyện trò chơi, có người nhắc u88, nhưng chủ đề lúc đó là cách in cho gọn chứ không phải chọn nơi nào. Với mình, bài này cho thấy vấn đề nằm ở luồng dữ liệu hơn là ở chiếc máy in.

Like
bottom of page