Dynamic value for a field

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
nirvana
User
Posts: 41

Dynamic value for a field

Post by nirvana »

Hi there,

I wanted to create a user registration page in which there is a field called "Register as" shown in checkboxes in which there are two values: Author and Publisher. Based on the selection of "Register as" field, I want to set the user level with the value '2' for the Publisher and '3' for Author. Can it be done using PHPMaker or do we need to create a client-side/server-side script to achieve the result? Any guidance would be appreciated. Thank you.


nirvana
User
Posts: 41

Post by nirvana »

I only wanted to share the quick possible solution to the problem although it doesn't set the value dynamically for the field value chosen. I am thinking to remove the "Register As" field and instead just use the UserLevel field and display only "Publisher" and "Author" without listing other userlevel values by using lookup table feature and filter during the lookup. I haven't implemented it yet but thought to share here to see if there are better ways to achieve the solution.


nirvana
User
Posts: 41

Post by nirvana »

I am posting again as I have found that using the filter in users table also restricts administrator to list all the users. Having the filter only on the registration page would help me. I'd appreciate if anyone could provide the way to achieve the result. Thank you.


mobhar
User
Posts: 11741

Post by mobhar »

Try to add condition based on current PageID, for example:

if (CurrentPageID() == "register") {
// your filter for registration page

} else {
// your filter for users table only

}


nirvana
User
Posts: 41

Post by nirvana »

Many thanks for your input! I applied that into users "Record_Selecting" event and it works fine for administrator's page while listing users in the list page. Can we also use same conditions for the lookup table?

The problem with the registration page is that although the userlvel field has been selected for the registration page, it doesn't appear in the page. All the other selected fields are visible in the registration. Have I missed something in the configuration?

I searched for the userlevel in the registration page, and you had already answered the query. So, if I create a database view, which tables must be joined in order to get the desired outcome in the registration page. I understood the part of "assigning necessary privileges" to the anonymous user to the database view. Thank you for your help!


nirvana
User
Posts: 41

Post by nirvana »

I forgot to mention the page in which you had provided answer to the query regarding similar problem:
http://www.hkvforums.com/viewtopic.php? ... on#p107380

So, if I create a database view, which tables must be joined in order to
get the desired outcome in the registration page. I understood the part of "assigning necessary privileges" to the anonymous user to the database view. Thank you for your help!


mobhar
User
Posts: 11741

Post by mobhar »

nirvana wrote:
Can we also use same conditions for the lookup table?

Yes, we can. You may use "Lookup_Selecting" server event under "Server Events" -> "Table-Specific" -> "Common". Please read "Server Events and Client Scripts" topic from PHPMaker Help menu for more info and examples.


nirvana
User
Posts: 41

Post by nirvana »

Since, the userlevel is not displayed in the registration page, I'll try to set the userlevel based on the query string just like @hendrika did in http://www.hkvforums.com/viewtopic.php? ... 1&p=107380.

I have been able to obtain the result using a query string and adding new values to the $rsnew array. I have copied the code that worked for me. If there is a better way to do this, please share your ideas. Thank you.

// Page Load event
function Page_Load() {

	//echo "Page Load";
	if(isset($_GET["as"])){
		$_SESSION["setUserLevel"] = @$_GET["as"];
		$UserLevel = $_SESSION["setUserLevel"];
	}
	else if(isset($_SESSION["setUserLevel"])){
		$UserLevel = $_SESSION["setUserLevel"];
	}

	if($UserLevel == 'pub') {
		//$rsnew['UserLevel'] = 2;
		$_SESSION["UserLevel"] = 2;
	}else if($UserLevel == 'aut') {
		//$rsnew['UserLevel'] = 3;
		$_SESSION["UserLevel"] = 3;
	}else {
		$_SESSION["UserLevel"] = 0;
	}
}

// Page Redirecting event
function Page_Redirecting(&$url) {

	if($_SESSION["UserLevel"]==0){
		$url = FullURL('login.php');
		AddHeader("Location", $url);
	}

}

    // Add record
protected function addRow($rsold = NULL)
{
	// UserLevel
	$rsnew['UserLevel'] = $_SESSION["UserLevel"]; // Set default User Level 
    }

mobhar
User
Posts: 11741

Post by mobhar »

nirvana wrote:
// Add record
protected function addRow($rsold = NULL)
{
// UserLevel
$rsnew['UserLevel'] = $_SESSION["UserLevel"]; // Set default User Level
}

What code was that? In which file did your write that code? Or, did you try to edit/modify the generated script file? If so, try to not modify the generated script file, because if you do that, then you have to re-modify again the generated script file each time you regenerate all the script files. In addition,

So, simply put the following code in "Row_Inserting" server event:

$rsnew['UserLevel'] = $_SESSION["UserLevel"]; // Set default User Level


nirvana
User
Posts: 41

Post by nirvana »

I just noticed that there's a way to edit the events for Registration page too. That's really good to know. This will really automate the code generation process.

I have used the Page_Load and Page_Redirecting event. Since there is no Row_Inserting event for the Registration Page, I think setting the user level from the session values can only be done by modifying the Register.php Class code.

Since the "register" Class extends Users class, I think the userlevel session values from the Registration page can be used in the Row_Inserting event in the Users class.


nirvana
User
Posts: 41

Post by nirvana »

I tried adding the following code to the Users class event "row_inserting" and it worked. So, I don't have to edit the generated page manually.

// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {
if(isset($SESSION["UserLevel"]))
$rsnew['UserLevel'] = $
SESSION["UserLevel"];
return TRUE;
}


Post Reply