Automated Forms

I was wondering if anyone knew how to make it when one of the members submits a response on one of the forms, and as soon as they press submit it automatically posts to another spot on the site that everyone can see not just members.

1 Like

Hi Nicholas,

That is possible. Here is the general outline of how to do that:

  • Add/insert the form information to a Collection (after submit)
  • Read/query the same information from the Collection to view on the given page.

Here is a general example:


// PAGE 1 - CODE - MEMBER PAGE

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;

export function btnSubmit_click(event) {
//Add your code for this event here:

let toInsert = { 
      "formValue1":  $w("#firstName").value,  
      "formValue2":  $w("#lastName").value,  
      "formValue3":  $w("#comment").value, 
      "formValue4":  wixUsers.currentUser.id	  
}; 

wixData.insert("MyFormResults", toInsert) 
	.then( (results) => { 
	    console.log("Form results submitted."); 
	} ) 
	.catch( (err) => { 
	    console.log(err); 
	} ); 

}


// PAGE 2 - CODE - NON-MEMBER PAGE

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;

$w.onReady(function () {
loadData();
})

function loadData() {

wixData.query("MyFormResults") 
  .eq("formValue4", wixUsers.currentUser.id) 
  .find() 
  .then( (results) => { 
    let firstItem = results.items[0]; 	 
        $w("#firstName").value = firstItem.formValue1; 
        $w("#lastName").value = firstItem.formValue2; 
        $w("#comment").value = firstItem.formValue3; 
}) 
.catch( (err) => { 
	console.log(err);  
} ); 

}

Note that the above WIX Code assumes that the Collection name is “MyFormResults” and the fields of that Collection are named: “formValue1”, “formValue2”, “formValue3” & “formValue4”. And, the following are the names of user input controls on both the member and non-member pages: $w(“#firstName”), $w(“#lastName”) & $w(“#comment”).

Nick

Make the form using Wix Code and submit it to a Database using Wix Data Insert Function

Make a Repeater or Table Linked to the Database.

You’ll have what you need.

Thank you guys