I want site member to add few more relevant details and upload supporting document after he/she is logged in.
I am using WIX editor. I have added members area and already using account settings and profile. I need user to add his business details and upload supporting document.
I created a custom page with input elements and connected them to CMS. But once submitted and user re-logins, I want those fields data to be shown as read only fields like we do in account setting page.
You have done almost everything, just do the below:
Duplicate the section where you are collecting the information on the custom page that you have already created.
Set the Dataset permission to read & write from write.
Set the duplicated input fields to read-only from the settings.
Connect the duplicated input fields to the same dataset (Mostly it would already be connected but advisable to perform a hygiene check).
You will need to add a bit of code to check if the logged in user has already submitted the information, if yes collapse the data collection section and expand the read only section, else the other way.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(async function () {
// Get the currently logged-in user
let user = wixUsers.currentUser;
let userId = user.id; // Unique ID of the logged-in user
// Reference to the dataset
let dataset = $w("#yourDataset"); // Change 'yourDataset' to the actual dataset ID
// Sections to be shown/hidden
let inputSection = $w("#inputSection"); // The section where users fill the form
let readOnlySection = $w("#readOnlySection"); // The duplicated read-only section
// Collapse both sections initially
inputSection.collapse();
readOnlySection.collapse();
// Check if the user is logged in
if (!user.loggedIn) {
// If user is not logged in, show input section (or redirect to login)
inputSection.expand();
return;
}
// Query the dataset to check if the user has already submitted data
wixData.query("yourDatasetName") // Replace with the actual dataset name
.eq("_owner", userId) // Finds records where the logged-in user is the owner
.find()
.then((results) => {
if (results.items.length > 0) {
// User has already submitted data, show the read-only section
readOnlySection.expand();
} else {
// User has NOT submitted data, show the input section
inputSection.expand();
}
})
.catch((err) => {
console.error("Error fetching user data: ", err);
inputSection.expand(); // Show input section in case of an error
});
});
What This Code Does
Checks if a user is logged in before showing the form.
Queries the dataset to see if the user has already submitted data.
Expands the appropriate section:
If data exists → show read-only section.
If no data exists → show input section.
Next Steps
Replace"yourDataset" with your actual dataset ID.
Replace"yourDatasetName" with your actual dataset collection name.
Ensure that the sections (#inputSection, #readOnlySection) are correctly linked in your page elements.
Let me know if you need any further clarification!
For the inputSection, add the same CMS to the page and set it to write-only. For the readOnlySection, connect it to the second dataset of the same CMS, ensuring it is read-only.
This should resolve the issue. Let me know if you need any further clarification!