Questions about forms
I am trying to set up a form for adding a new record in a section or editing existing records from this section. The name of the form is "various-form.php" corresponding to the section named "Various". I come across the following issues:
1. I have ticked the "Allow editing existing records (advanced feature)", but when I load the "various-form.php" file I can only see the "Add record" option. I cannot find any link to edit any existing records. Is it something I should do? Is it possible to have a table with a list of the records I have created (i.e. name, date, etc) and choose the one I would like to edit from this list?
2. I have ticked the "Require users to be logged in (requires Website Membership plugin)", and when I open the page ("/various-form.php") I get back the message "You must log in to use this form!". Instead of just a simple text message I would prefer to have a link sending the user to log in or the log in form from the Website Membership plugin. Is it possible to do it?
3. Each form (i.e. "various-form.php") is created in one single page containing all the fields of the section, and at the bottom of the page there is the button "Submit". For the user's facilitation, I think it would be better to be able to split the form into smaller form-subsections, each one connecting to the next or previous one with a "Next" or "Previous" button at the end of each form-subsection, leaving the "Submit" button for the last form-subsection. In other words, to create a multi-page form. Is it possible to divide the form into smaller form subsections and create a multi-page form and how can it be done?
Thank you in advance, and best wishes for 2022!!
1: To use the form to edit a record, you need to specify the record num in the URL, e.g. "various-form.php?num=123". A simple way to have a list of all entries with edit links would be to create a List Page for the Various section, and generate an edit link something like this:
<a href="various-form.php?num=<?php echo $record['num']; ?>">Edit</a>
2: You should be able to replace that message with the following Website Membership function to redirect to the login page:
Let me know if you have any other questions!
To accomplish what you're asking you can use the createdBy function built into CMSB to return only those records created by the specific user who is logged in at the moment.
Do a search for createdBy in the CMSB Cookbook > 'Subscribers Only' > 'Access the complete cookbook' and you'll find a number of examples that can be easily modified to give you the result you're after.
Hope that helps and have a safe, healthy and prosperous New Year
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
As Jerry says, to load only records created by the current user, you'll need to filter using the createdByUserNum field. The most simple version would just be adding something like this to the getRecords options:
'where' => mysql_escapef('createdByUserNum = ?', $CURRENT_USER['num']),
Note that there are some cases where this might not work as expected depending on your Website Membership plugin config (e.g. using a different member table than default) but if users are both adding and viewing the entries on the front-end this should generally work just fine.
As well, this doesn't account for any permissions - if you want particular users to be able to view all records that would require some additional logic.
Let me know any other questions!