This topic is locked

How to hide the ADD button after 1 record has been entered?

11/10/2010 3:49:10 PM
PHPRunner General questions
K
karmacomposer author

My client wants some of my forms to only be added one time. They want me to disable the ability to add after one entry. How can this be done?
Mike

J
Jane 11/11/2010

Hi,
use List page: Before display event on the Eventstab for this purpose.

Here is a sample:

$rstmp = CustomQuery("select count(*) as count_R from TableName");

$datatmp = db_fetch_array($rstmp);

if ($datatmp["count_R "]>1)

$xt->assign("add_link",false);



Probably you'll need to add WHERE statement to the SQL query in this code to select records for current user only (if you useUser can see and edit their own records only security method on the Advanced security settings dialog on the Security tab).

K
karmacomposer author 11/11/2010



Hi,
use List page: Before display event on the Eventstab for this purpose.

Here is a sample:

$rstmp = CustomQuery("select count(*) as count_R from TableName");

$datatmp = db_fetch_array($rstmp);

if ($datatmp["count_R "]>1)

$xt->assign("add_link",false);



Probably you'll need to add WHERE statement to the SQL query in this code to select records for current user only (if you useUser can see and edit their own records only security method on the Advanced security settings dialog on the Security tab).


I am sure I have not done this right, here is my code:
$rstmp = CustomQuery("select count(*) as count_R from CandidateCC");

$datatmp = db_fetch_array($rstmp);

if ($datatmp["count_R "]>1)

$xt->assign("add_link",false)
Is the variable count_R something I need to change or is it the COUNT php command?
What else do I need to alter and do I use the WHERE statement on the IF line or the 1st line? What do I do with the $xt variable?
I do have the security for that table set to USERS CAN SEE AND EDIT THEIR DATA ONLY.
What else do I need to do to make this work?
Thank you for your help.
Mike

J
Jane 11/11/2010

Here is a sample with WHERE statement:

global $strTableName;

$rstmp = CustomQuery("select count(*) as count_R from CandidateCC where OwnerID='".$_SESSION["_".$strTableName."_OwnerID"]."'");

$datatmp = db_fetch_array($rstmp);

if ($datatmp["count_R "]>1)

$xt->assign("add_link",false);



If you'll have difficulties publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

K
karmacomposer author 11/11/2010



Here is a sample with WHERE statement:

global $strTableName;

$rstmp = CustomQuery("select count(*) as count_R from CandidateCC where OwnerID='".$_SESSION["_".$strTableName."_OwnerID"]."'");

$datatmp = db_fetch_array($rstmp);

if ($datatmp["count_R "]>1)

$xt->assign("add_link",false);



If you'll have difficulties publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.


Here is the code I changed from yours:
global $strCandidateCC;

$rstmp = CustomQuery("select count(*) as count_R from CandidateCC where CandidateCCID='".$SESSION["".$strCandidateCC."_CandidateCCID"]."'");

$datatmp = db_fetch_array($rstmp);

if ($datatmp["count_R "]>1)

$xt->assign("add_link",false);
Now, is strTableName a command or do I change it to the table name?
I uploaded this to my demo account (mfelker@mfelkerco.com).
Mike

Sergey Kornilov admin 11/11/2010

$strTableName is a variable populated with the current table name. You can leave it as is.

K
karmacomposer author 11/11/2010



$strTableName is a variable populated with the current table name. You can leave it as is.


Right. The code fragment does not cause errors, but it does not work either. I created one record in the CandidateCC table (form). When I log in or go back to the list, the ADD NEW button should be gone, but it's still there.
Mike

Sergey Kornilov admin 11/11/2010

Mike,
you need to print this SQL query on the page to see if it looks right. You can also post it here or run against your database in phpMyAdmin to see what data it returns.
Print SQl query use echo command i.e.

echo "Your SQL query here";

K
karmacomposer author 11/11/2010



Mike,
you need to print this SQL query on the page to see if it looks right. You can also post it here or run against your database in phpMyAdmin to see what data it returns.
Print SQl query use echo command i.e.

echo "Your SQL query here";


In PHPMyAdmin the following formula gave the following result:
select count() as count_R from CandidateCC
gave the result: count_R = 4
There are a total of 4 records in that database, so it worked.
The following gave count_R a result of 1:
select count(
) as count_R from CandidateCC where CandidateCCID = 70
70 being the last record in that database.
I do have a question. Since the person logging in is the only one logging in, do I even need a WHERE statement?
What is supposed to happen is that the person registers as a Candidate (either CC or SWT) and then enters one record. After that, the ADD NEW button needs to disappear or the ability to add a new record needs to be taken away.
Mike

Sergey Kornilov admin 11/11/2010

That's a good question actually. I think you still need to calculate the number of records this person added. You have to cover the following scenarios:

  1. Someone registers and don't add any records. Next day she logs in and wants to add one. You don't want to force the user register second time.
  2. Even if you hide the button someone can proceed to the Add page directly. This means you need to perform this calculation right on the Add page i.e. in BeforeProcess event and redirect user somewhere if record was added already.

K
karmacomposer author 11/11/2010



That's a good question actually. I think you still need to calculate the number of records this person added. You have to cover the following scenarios:

  1. Someone registers and don't add any records. Next day she logs in and wants to add one. You don't want to force the user register second time.
  2. Even if you hide the button someone can proceed to the Add page directly. This means you need to perform this calculation right on the Add page i.e. in BeforeProcess event and redirect user somewhere if record was added already.


Perhaps I should do this AFTER a record is successfully added. My client is a PAIN IN THE BUTT and wants things to look and act the way she wants it, which makes more work for me.
If someone registers but logs in the next day, you should still see the ADD NEW button regardless. I need it to disappear AFTER one record is created. In essence, they should not be allowed to enter a second record at all.
Mike

Sergey Kornilov admin 11/12/2010

You need to stick to the original idea supplied by Jane - checking the number of records that belong to this client and hide add link if record exists already.