Search.../

rsvp

Gets an object containing RSVP functionality.

Description

Use the RSVP object to create an RSVP for an event.

Note:

To work with the Wix Events API, you need to publish your site.

Type:

RsvpRead Only

Was this helpful?

Create and submit a registration form

Code Example

Copy Code
1import wixEvents from 'wix-events';
2import wixData from 'wix-data';
3
4let eventId;
5
6// Run a query that will return only one event. Add
7// additional filtering to the query if necessary.
8wixData.query("Events/Events")
9 .eq("title", "My Event")
10 .find()
11 .then( (results) => {
12 if(results.items.length > 0) {
13 eventId = results.items[0]._id;
14 }
15 else {
16 console.log("Could not find event");
17 }
18 });
19
20$w.onReady(function () {
21 $w("#submit").onClick( () => {
22 const formValues = getFormValues();
23
24 wixEvents.rsvp.createRsvp(eventId, formValues)
25 .then( (result) => {
26 console.log("RSVP created.")
27 } )
28 .catch( (error) => {
29 console.log(`Error message: ${error.message}`);
30 if(error.fields) {
31 console.log(`Incorrect fields: ${error.fields}`);
32 }
33 } );
34 } );
35});
36
37function getFormValues() {
38 return [
39 {"name": "rsvpStatus", "value": "YES"},
40 {"name": "firstName", "value": $w("#firstName").value},
41 {"name": "lastName", "value": $w("#lastName").value},
42 {"name": "email", "value": $w("#email").value},
43 {"name": "custom", "value": $w("#foodAllergies").value},
44
45 // When a form contains an address, the way you format the
46 // address information for submission depends on what type
47 // of input elements you use to gather that information.
48
49 // Wix address input element.
50 {"name": "address", "value": $w("#address").value},
51
52 // Single element which is not an address
53 // input element, such as a text input.
54 {"name": "address", "value": [$w("#address").value]},
55
56 // Multiple elements for the
57 // various parts of an address.
58 {
59 "name": "address",
60 "value": [
61 $w("#street").value,
62 $w("#city").value,
63 $w("#state").value,
64 $w("#country").value,
65 $w("#postalCode").value
66 ]
67 },
68
69 // When a form contains an input for adding more guests to an
70 // RSVP, format the guest names for submission in an array
71 // where each element is the full name of a guest.
72 {"name": "additionalGuests", "value": $w('#additionalGuests').value},
73 {
74 "name": "guestNames",
75 "value": [
76 `${$w("#guest1FirstName").value} ${$w("#guest1LastName").value}`,
77 `${$w("#guest2FirstName").value} ${$w("#guest2LastName").value}`,
78 ]
79 }
80 ];
81}