Jump to content
  • 1

Hide Button if "Receivername" is not found in UserAuthentication table


DaveC2019

Question

I have a field called "receiversname" which is the second input field on my form. I am trying to make the form so that when the receiver's name is entered a script or whatever method will query the "UserAuthenticationTable" and check the field "combined_user_name" to see if the receiver's name exist. I the name does not exist the button should not be available and the page should not be able to be submitted even if the user uses a virtual keyboard like what is found on mobile devices. Here is a link to the datapage: https://c6fot106.caspio.com/dp/acef600012e3392a45cf4611abbd

The credentials to login are "michaelt@tippytv" and pw is "qwe123qwe". Here is a receiver's name that is in that database to be used for testing:  "jameskirk@tippytv"

Any help with this would be greatly appreciated. Thanks!

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hi DaveC2019,

What you need to do is to add a virtual field in your submission form, then set its form element as a calculated field and use the SQL code below to check if the receiver name that the user entered can be found in your user authentication table.

image.png.0b45ac54c90d9da5677c98f51bcac9b7.png

I've also added the exported copy of the sample DataPage that I've worked with, just import it to your account so that you can see how it works.

Kind regards,

TsiBiRu

You can try using the SQL below, the code below will get the a value from your 'combined_user_name' field in your  'UserAuthentication' table if there is a matching record. If it will not work, just ensure that field name and table name is correct.

SELECT combined_user_name 
FROM UserAuthentication 
WHERE combined_user_name = target.[@field:InsertRecordreceivername]

After that, I've hidden the virtual field using the method in this article

Then add the JS code below on the footer of your Datapage, just replace the number of the 'cbParamVirtual1' in the code below to match the number of your virtual field. Let's say that the virtual field that you have added to use the SQL code above is 'Virtual5', then just update 'cbParamVirtual1'  to 'cbParamVirtual5'

<script type="text/javascript">
  
 // This function will run if the value in our Virtual1 is change 
document.getElementsByName('cbParamVirtual1')[0].onchange = function() {myFunction()};
function myFunction() {
  
// This code will get the value of Virtual1
var test = document.getElementsByName('cbParamVirtual1')[0].value;

// This code will check Virtual1 is empty, and hide the submit button if it is
if (test.length == 0){
document.getElementById("Submit").style.display = "none";
}

else{document.getElementById("Submit").style.display = "block";}

}
</script>

 

CaspioData_2019-Mar-27_1853.zip

Link to comment
Share on other sites

  • 0

If you also wanted to check if the inputted value for "receiversname" field contains or is in the "combined_user_name" field  of the table "UserAuthenticationTable", then you can try this Formula instead:

CASE
WHEN ([@field:receiversname] IN (SELECT combined_user_name FROM UserAuthenticationTable))
THEN 'Yes'
ELSE 'No'
END

 

Link to comment
Share on other sites

  • 0

Hi @DaveC2019,

Just follow the steps that I've provided in my previous comment, especially adding a virtual field where we will use an SQL statement to check if the inputted receiver name is in your table. And just update the 'cbParamVirtual1' in the code below accordingly 

<script type="text/javascript">
  
 // This function will run if the value in our Virtual1 is change 
document.getElementsByName('cbParamVirtual1')[0].onchange = function() {myFunction()};
function myFunction() {
  
// This code will get the value of Virtual1
var test = document.getElementsByName('cbParamVirtual1')[0].value;

// This code will check Virtual1 is empty, and hide the submit button if it is
if (test.length == 0){
document.getElementById("Submit1").style.display = "none";
}

else{document.getElementById("Submit1").style.display = "block";}

}
</script>

I've updated the code above, it will be hiding the  'Leave a Tip' button in your submission form. If you will still be having issue implementing my solution, just provide me with an exported copy of your DataPage with its dependencies.

image.png.a58ffa32cda9b36eab32a6c962636716.png

And if your table contains sensitive data, just click on 'Tables' then click on your table and select'Without Data'

image.thumb.png.9d87767ee4657c950f1196ae36fe5b78.png

 

Kind regards,

TsiBiRu

 

Link to comment
Share on other sites

  • 0

If the receiver name should be a valid entry then you can have a dropdown so they can select from. If you do not want to present the names, a workaround would be creating an authentication based on "UserAuthenticationTable" and only include  combined_user_name (must be unique in the table) for users to enter (no pass fields). If this is a valid entry then you can proceed and enter more data. User does not have to enter combined_user_name again on this form as it can be received from Authentication.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...