Record selector in independent page.

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Record selector in independent page.

Post by DevGiu » 2016-05-30 07:57

Version 5.50

Hi,

I would like, after login, to redirect to a page when you have to choose a value from a dropdown, and save this value on SESSION.

Redirection works, but I can't get dropdown working. I based on Udemy class of lookup search filters for HTML. I created a myfile.php in project root.

Then:

Code: Select all

<?php
	$currDir = dirname(__FILE__);
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	include_once("$currDir/header.php");

	/* grant access to all logged users */
	$mi = getMemberInfo();
	if(!$mi['username'] || $mi['username'] == 'guest'){
		echo "Access denied";
		exit;
	}
?>

<div style="margin-top: 20px;">
	<label>Choose Company</label>
	<div style="max-width: 550px;"><span id="EmpresaDropDown"></span></div>
</div>

<script>
	$j(function(){
		/* display a drop down of categories that populates its contents from ajax_combo.php */
		$j('#EmpresaDropDown').select2({
			ajax: {
				url: 'ajax_combo.php',
				dataType: 'json',
				cache: true,
				data: function(term, page){ return { s: term, p: page, t: 'empresa', f: 'id' }; },
				results: function(resp, page){ return resp; }
			},
			width: 550
		}).on('change', function(e){
			//$j('#CategoryID').val(e.added.text);
		});
	})
</script>

<?php
	include_once("$currDir/footer.php");
?>
But dropdown keep spining without showing me the record in database.

There are any tutorial on custom pages out there? I think this is a basic need/feature (all projects needs pages don't connected directly to a database but working with its data to do some proccess) but it's difficult for me to find this information.

It's easy what I want to do. I just want to show a dropdown with a list of companies, and once a company is selected and press a button, saves company ID on a session var (tu use in all other apps) and redirects to home.
/Giuseppe
Professional Outsourcing Services

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Record selector in independent page.

Post by DevGiu » 2016-05-31 07:06

Ok, Looking into the code of ajax-combo.php, I saw the problem. I was asking to ajax-combo.php directly the table and the field I want to return, when you have to pass a table with a reference of the table you want.

Instead

Code: Select all

data: function(term, page){ return { s: term, p: page, t: 'empresa', f: 'id' }; },
Should be something like

Code: Select all

data: function(term, page){ return { s: term, p: page, t: 'salesman', f: 'company_id' }; },
But:
How to call directly for data on a table, or pass directly an SQL? Sometimes you can need to have a dropdown in some custompage, and have to use a "random" related table is not intuitive for the developer when you are out of context of a table. I mean. Makes sense if you are creating a filter page for products, and you want to retrieve a value from a related table to product. But, If I'm creating a custom page, called directly after login, where I'm out of context of any other table of the system, where I need to show a dropdown with companies, and do some proccess on selection, is not intuitive to use something like

Code: Select all

t: 'salesman', f: 'company_id' 
to show a list of companies, where my process has nothing to do with salesman table.

My question is, if there are some AppGini way to do this, or I have to build my own "ajax-combo.php" to do what I want.

I hope I explained correctly.
/Giuseppe
Professional Outsourcing Services

TheNoLifer
Veteran Member
Posts: 67
Joined: 2015-06-06 12:10

Re: Record selector in independent page.

Post by TheNoLifer » 2016-06-05 02:15

I'm not entirely sure I understand - but I will try to help with the first part - the drop-down box.

I have a custom Contact Page here - https://ada.abernyte.org/contact.php - that contains a drop down box, populated by a SQL query against one of my appgini tables. Is that what you are looking for?

In the drop down on my page - select the value "Request Access to Abernyte Materials not Available on ADA" and a second box will appear. This second box selects its values like this;

Code: Select all

//Connect to Database with custom login file outwith appgini login file 
include 'db/custom_db_login.php';

$result = mysql_query("SELECT ContentItem.id, CONCAT_WS(' ', ContentItem.id, '-', ContentItem.title) AS item, ContentItem_followup.follow_up_flag FROM ContentItem
INNER JOIN ContentItem_followup
ON ContentItem.mark_for_review_id = ContentItem_followup.id
WHERE ContentItem_followup.follow_up_flag = 'OFFLINE'") or die(mysql_error());
and then this block of html creates the drop down and populates it with the values;

Code: Select all

<div class="element-offline" title="Offline File Request" id="offline"><label class="title">Content Items with Offline Content</label><div class="large"><span><select name="offlinecontent" >
<option value="Please select the relevant Content Item">Please select the relevant Content Item</option>
<?php while ($row = mysql_fetch_assoc($result)) {echo '<option value='.$row['item'].'>'.$row['item'].'</option>';} ?>
</select><i></i></span></div></div>
I'm not sure about the session variable part, sorry! I hope this was relevant to your question though.

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: Record selector in independent page.

Post by DevGiu » 2016-06-05 17:47

Thanks for your answer.

Yes, I'm looking something similar but more "AppGinied".
Idea is to redir from a login to a custom page. In this custom Page, I want to select a value from a dropdown and then redir to the menu (saving the value selected on a session variable). As far as I saw, Dropdowns works against ajax_combo.php but in ajax_combo.php are defined the relations of the FK of every table, but What I want to retrieve, is the content of a table, without taking in consideration any relationship. What I asked is if there are some existing way to just throw an SQL from select2, or I must to crteate my "ajax_combo" to return the results from my query.

I hope I explained better.
/Giuseppe
Professional Outsourcing Services

Post Reply