10 Replies Latest reply on Mar 24, 2014 1:45 AM by ArmutElma

    How to create a registration form and check for existing usernames

    ArmutElma

      Title

      How to create a registration form and check for existing usernames

      Post

           Hello,

           I'm trying to create a "simple" register script. I've created 4 fields:

             
      1.           username
      2.      
      3.           UnameCheck
      4.      
      5.           password
      6.      
      7.           SetPassword

            

           So user enters a preferred username into the UnameCheck field.

           Script aims to search the username field against what the user just entered into UnameCheck field to see if that username is already in use.

           If found, show custom dialog box to prompt user to enter a different username.

           Else set username to UnameCheck

           Here's what I've done so far. It's not doing what I intend to do. I know the issue is with comparing two fields and I'm pretty sure I'm not doing it right. So please help:

      Register Script:

      New Record/Request

      Show Custom Dialog ["Register"; "Please provide a username and password" TableName:UnameCheck; TableName;SetPassword"

      Perform Script ["UsernameCheck"]

      UsernameCheck Script:

      Set Error Capture [On]

      Find Matching Records [Constrain; TableName:username]

      If [Get (LastError) = 401]

           Set Field [TableName::username; TableName:UnameCheck]

      Else

         Show Customer Dialog ["Username in use"; "If you have already registered, please use the login link. Otherwise please pick a different username"]

         Exit Script[]

      End If

        • 1. Re: How to create a registration form and check for existing usernames
          philmodjunk

               Your script never enters the next from unameCheck into UserName as search criteria.

               But I suggest a simpler method:

               Make unameCheck a global field. Define this self join relationship and use it to check for pre-existing values:

               TableName::UnameCheck = TableName 2::UserName

               A conditional format can then be used to warn the user if they enter a matching name. A script to create the new record with Matching name would look like this:

               If [ IsEmpty ( TableName 2::UserName ) // User name has not been used ]
                  New Record/Request
                  Set Field [TableName::UserName ; TableName::UnameCheck ]
               Else
                  Show Custom Dialog ["This user name already exists..."]
               End If

               Note that no new record is created until the user name is confirmed as unique.

          • 2. Re: How to create a registration form and check for existing usernames
            ArmutElma

                 I've not worked with global fields before, and still learning FM. Pretty sure I'm not getting this right... Below is the screenshot of what I've understood from your suggestion. First created another table and placed two fields in there. Set UnameCheck to global. Then changed scripts to mimic the above. Tied Register script to a button so it opens up a customer dialog box and asks for username and password. And the rest is in the pictures. However, every time I do that although it creates a new record, the username field for ALL records is set to the last entered username...

                  
            • 3. Re: How to create a registration form and check for existing usernames
              philmodjunk

                    "I created a new table" is the problem. You did not create a "self join".

                   You should not create a new table for this on the tables tab. Instead, select Buddy Program in Manage | Database | Relationships and click the duplicate button (two green plus signs). This creates a new Tutorial: What are Table Occurrences? rather than a new table. This is necessary for a self join--a relationship between two occurrences of the same table.

              • 4. Re: How to create a registration form and check for existing usernames
                ArmutElma

                     Thanks Phil! That worked. I can only apologize for my ignorance. I dive in head first and hope to figure it out as I go along...

                • 5. Re: How to create a registration form and check for existing usernames
                  philmodjunk

                       No apology needed. When I respond to a question, I often have no real way to tell the level of understanding/expertise of the original poster. I then guess and if I guess wrong as I did here, the poster simply needs to follow up with a response in order to gain that needed additional explanation--which is what you did.

                  • 6. Re: How to create a registration form and check for existing usernames
                    ArmutElma

                         Can I be cheeky and ask for a bit more help then? 

                         Now that I can register "users", I need to make a login script. And depending on who it is, I want them to go to a specific record in the database and nothing else. I've been trying different things for the last ~2 hours and I'm just not getting anywhere. I don't know why it's so hard to do a simple search to find records that match a criteria... 

                          

                    • 7. Re: How to create a registration form and check for existing usernames
                      philmodjunk

                           Looks like Buddy Program 4 should link to Buddy Program.

                           By why set up your own log in script and layouts when you can use Manage | Security to set up your account name and passwords to control access? Scripts and layouts can be set up that work with Manage | Security to create the needed accounts and assigned passwords.

                      • 8. Re: How to create a registration form and check for existing usernames
                        ArmutElma

                             Because if/when this is built, it'll be sent out to remote areas where I have no control over who needs to use and have access to...

                             I was hoping to create a simple script that asks for a new user to provide a username and password, and use that information to logon whenever this person uses the application. The same application will be used by several people so I didn't want one to access the other one's records. So one user can only input only one record, pretty linear table structure. 

                             I'll probably have to read much more into it and see how I can do this. Thanks for your help. Have a great weekend!

                        • 9. Re: How to create a registration form and check for existing usernames
                          philmodjunk
                               

                                    Because if/when this is built, it'll be sent out to remote areas where I have no control over who needs to use and have access to...

                               Which does not mean that you have to manually create accounts and passwords. You can set up a layout with scripts and fields that enable users to create their own accounts and passwords. Take a look at the script steps for working with accounts and passwords.

                               And you may find this of interest:

                               

                                    See "Editing record access privileges" in FileMaker Help and check out this particular sub section: "Entering a formula for limiting access on a record-by-record basis" for a description of how to set this up.

                          • 10. Re: How to create a registration form and check for existing usernames
                            ArmutElma

                                 Oh thanks! That's exactly what I wanted to do. Thank you so much!