Ajax dont works populating a form - joomla2.5

Hey anyone can help me with this problem ?
I have this issue with my code, two files:
1 - test.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<script>
var url = "getagentids.php?param=";
function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText.split(",");
document.getElementById('formality').value = results[0];
document.getElementById('fullname').value = results[1];
document.getElementById('sex').value = results[2];
document.getElementById('id').value = results[3];
document.getElementById('joindate').value = results[4];
document.getElementById('jobtitle').value = results[5];
document.getElementById('city').value = results[6];
document.getElementById('typeofsalary').value = results[7];
document.getElementById('contract_type').value = results[8];
}
}
function getagentids() {
var idValue = document.getElementById("email").value;
var myRandom=parseInt(Math.random()*99999999); // cache buster
http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject();
</script>
</head>
<body>
<form name="schform">
<table bgcolor="#dddddd">
<tbody>
<?php
echo $param;
include '../../../connect.php';
$db =& JFactory::getDBO();
$query = "SELECT email FROM dbemployeekpw";
$db->setQuery($query);
$result = $db->loadObjectList();
$email = $result[0];
echo " <select size='1' name='email' id='email' onChange='getagentids()' required >
<option value=''> Seleccione </option>";
foreach($result as $email)
{
echo "<option value='".$email->email."'>".$email->email."</option>";
}
echo "</select>"
?>
<tr><td>Formality</td><td><input id="formality" type="text" name="formality"></td></tr>
<tr><td>Fullname</td><td><input id="fullname" type="text" name="fullname"></td></tr>
<tr><td>Sex</td><td><input id="sex" type="text" name="sex"></td></tr>
<tr><td>Id</td><td><input id="id" type="text" name="id"></td></tr>
<tr><td>Joindate</td><td><input id="joindate" type="text" name="joindate"></td></tr>
<tr><td>Jobtitle</td><td><input id="jobtitle" type="text" name="jobtitle"></td></tr>
<tr><td>City</td><td><input id="city" type="text" name="city"></td></tr>
<tr><td>Typesalary</td><td><input id="typeofsalary" type="text" name="typeofsalary"></td></tr>
<tr><td>Contract Type</td><td><input id="contract_type" type="text" name="contract_type"> </td></tr>
<tr><td><input size="60" type="reset" value="Clear"></td><td></td>
</tr>
</tbody></table>
</form>
</body>
</html>
and..
2 - getagentids.php
<?php
//$param = $_GET["param"];
include '../../../connect.php';
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe#kantarworldpanel.com'";
$db->setQuery($query);
$results = $db->loadObjectList();
foreach ( $results as $result )
{
$formality = $result->formality;
$fullname = $result->fullname;
$sex = $result->sex;
$id = $result->id;
$joindate = $result->joindate;
$jobtitle = $result->jobtitle;
$city = $result->city;
$typeofsalary = $result->typeofsalary;
$contract_type = $result->contract_type;
$textout = $formality.",".$fullname.",".$sex.",".$id.",".$joindate.",".$jobtitle.",".$city.",".$typeofsalary.",".$contract_type;
}
echo $textout;
?>
But ajax dont works, only works if I put this :
$query = "SELECT * FROM dbemployeekpw WHERE email = 'camilo.uribe#kantarworldpanel.com'";
instead this:
$query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";
But I need that the code works with second one :(
Anyone can help me with this problem ?
Thanks !!
SOLVED (works like a charm!!):
I change this:
$jinput = JFactory::getApplication()->input;
$param = $jinput->get('param', 'param', 'filter');
instead this:
$param = $_GET["param"];
and I'm still with:
$query = "SELECT * FROM dbemployeekpw WHERE email = '".$param."'";
because this code don't works for me:
$query->select($db->quoteName('*'))
->from($db->quoteName('dbemployeekpw'))
->where($db->quoteName('email') . ' = '. $db->quote($param));
Many Thanks #lodder

Before anything, lets see if the $param variable is correct and gets the value. Add the following which one the form is processed, will display the value. If the result is NULL then you firstly need to ensure you get the correct value. If you do get the correct value, then carry on reading.
Just on a side note, I would recommend looking at the following link rather than using $_GET:
http://docs.joomla.org/Retrieving_request_data_using_JInput
Lets now use up to date coding standards for you database query:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('*'))
->from($db->quoteName('dbemployeekpw'))
->where($db->quoteName('email') . ' = '. $db->quote($param));
$db->setQuery($query);
$results = $db->loadObjectList();
Hope this helps

Related

Custom Repeater Template code in Ajax Load More plugin not compatible with PHP8

We are hosted by WP Engine, so I tested our dev site's compatibility with PHP8 to comply with the upcoming requirement, and ran into a problem. We have listing pages that are automatically generated using a custom coded repeater template within the Wordpress Ajax Load More plugin, in conjunction with ACF. I've picked through it line by line, but can't figure out what's causing the pages to break.
At first, when I tested PHP8 compatibility earlier this year, the repeater pages returned a fatal error. Now I get a partial listing on some, and just a Load More button on others, and the Load More button doesn't work in any instance.
Everything works just fine with PHP 7.4, FWIW.
Here is one of our listing pages for reference:
https://smartorg.com/resources/principles-strategic-portfolio-management/
Here is the custom code:
<?php
$article_link = get_permalink( $post->ID );
$article_time = get_post_meta(get_the_ID(), 'length', TRUE);
$article_time = str_replace( array("min"), '', $article_time);
$article_type = get_post_meta(get_the_ID(), 'type', TRUE);
$article_val = '';
$timer = 'min';
if($article_type == 'Article') {
$article_val = 'read';
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$Words = str_replace(' ', $word_count);
$readingtime = ceil($word_count / 280);
$timer = " min";
$totalreadingtime = $readingtime . $timer;
$article_time = $totalreadingtime;
} else if($article_type == 'Video') {
$article_val = $timer . ' watch';
} else if($article_type == 'Webinar') {
$article_val = $timer . ' watch';
} else if($article_type == 'Audio') {
$article_val = $timer . ' listen';
} else{
$article_val = '';
}
$category = get_the_category( $post->ID );
// echo $atts['is_archive'];
$yoast_meta = get_post_meta(get_the_ID(), '_yoast_wpseo_metadesc', true);
if ($yoast_meta) {
$meta = $yoast_meta;
} else{
$meta = '';
}
?>
<div class="pm-main-cont">
<div class="pm-col-1">
<div class="pm-red-box"></div>
<div class="pm-article-img">
<a href="<?php echo $article_link; ?>">
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<img src='<?php echo $image[0]; ?>' alt="post thumbnail" />
</a>
</div>
</div>
<div class="pm-col-2">
<div class="pm-article-content">
<h5><?php echo the_title(); ?></h5>
<!-- <p><?php echo the_excerpt(); ?></p> -->
<p><?php echo $meta; ?></p>
<p class="pm-time-type"><img src="http://smartorg.com/wp-content/uploads/2020/09/<?php echo $article_type; ?>.png" alt="<?php echo $article_type; ?>-icon" />
<span><?php
echo $article_time; ?>
<?php echo $article_val; ?>
</span></p>
</div>
</div>
</div>

Dynamic options not showing up after adding Chosen

Initially I had everything working with Chosen plugin when the options were directly passed from python to the html template.
I then tried to make the options filled dynamically depending on one of the buttons clicked, the options were not rendered so nothing showed up (but if I inspect the Elements, each optgroup was filled correctly with options).
And if I remove $(".chosen-select").chosen() , then the options are rendered.
Here's my code:
<!-- language: html -->
<div class="container" style="margin:auto; padding-top: 2%; text-align: center;">
<b>Choose the Program:</b>
<ul id="programs" class="no-bullets" data-tag="programList">
<li onclick="selectProgram(this)">Type1</li>
<li onclick="selectProgram(this)">Type2</li>
<li onclick="selectProgram(this)">Type3</li>
</ul>
<b>Choose the Documents:</b>
<select id="documentOptions" name="documents" data-placeholder="Your Documents" class="chosen-select" multiple>
<optgroup label="Group1" id="Group1"></optgroup>
<optgroup label="Group2" id="Group2"></optgroup>
<optgroup label="Group3" id="Group3"></optgroup>
</select>
</div>
<!-- language: lang-js -->
<script>
$(".chosen-select").chosen()
function selectProgram(el){
Array.prototype.slice.call(document.querySelectorAll('ul[data-tag="programList"] li')).forEach(function(element){
element.classList.remove('selected');
});
el.classList.add('selected');
programSelected = el.innerText;
//console.log(programSelected);
fetch(`/api/data/get_program/${programSelected}`)
.then(function(response){
return response.json();
}).then(function(documentList){
documentListJSON = {"documents":documentList};
//console.log(documentListJSON);
$.ajax({
type: 'POST',
url: '/api/data/programDocuments',
contentType: 'application/json',
data: JSON.stringify(documentListJSON),
success: function( allDocuments ){
console.log(allDocuments);
const Type1_Options = document.getElementById("Group1");
const Type2_Options = document.getElementById("Group2");
const Type3_Options = document.getElementById("Group3");
Type1_Options.innerHTML = "";
Type2_Options.innerHTML = "";
Type3_Options.innerHTML = "";
let docs_type1 = allDocuments['type1'];
let docs_type2 = allDocuments['type2'];
let docs_type3 = allDocuments['type3'];
// create list of options
var options = "";
for(var i = 0; i<docs_type1.length;i++){
options += "<option value='" + docs_type1[i] +"'>" + docs_type1[i] + "</option>";
}
Type1_Options.innerHTML += options;
$(Type1_Options).appendTo('#Group1');
var options = "";
for(var i = 0; i<docs_type2.length;i++){
options += "<option value='" + docs_type2[i] +"'>" + docs_type2[i] + "</option>";
}
Type2_Options.innerHTML += options;
$(Type2_Options).appendTo('#Group2');
var options = "";
for(var i = 0; i<docs_type3.length;i++){
options += "<option value='" + docs_type3[i] +"'>" + docs_type3[i] + "</option>";
}
Type3_Options.innerHTML += options;
$(Type3_Options).appendTo('#Group3');
}
})
})
}
</script>
I'm quite new to JavaScript and Jquery..Could someone please help explain why this happens?
Any help is very much appreciated. Thank you!

How to use if statments to run second function Google script

I am trying to speed up my script, right now I currently have it set up so that on a button click a custom dialog (HTML) appears asking some questions. On submit, it calls out a gs function to pull the info back as variables. Depending on the first answer I have a series of If statments that trigger. Each of them pull up a different template, make a copy, populate some cells, emails it to you, and then dumps the data into a tracker. Each of them are different so the script is rather long - is there a way to have each if statment its own function? Would this even help the speed? I am new to scripting so any feedback is appreciated. Below is the Code and HTML
function onOpen() //adds option to top row in case buttons are not working.
{
var ui = SpreadsheetApp.getUi();
ui.createMenu('Create Doc.')
.addItem('Create Tracked Document', 'addItem')
.addToUi();
}
function addItem()//starts the initiation process
{
var html = HtmlService.createTemplateFromFile('form')
.evaluate()
.setWidth(300)
.setHeight(550);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Create New Document');
}
function addNewItem(form_data)//pulls data from form
{
var ui = SpreadsheetApp.getUi();
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var n = new Date();
var now = ((n.getMonth()+1) + "/" + n.getDate() + "/" + n.getFullYear());
var doctyp = form_data.Document_Type;
var name = form_data.Name;
var title = form_data.Title;
var platform = form_data.Platform;
var area = form_data.Area;
var rota = form_data.Rotation;
var works = form_data.WorkSt;
var recipient = Session.getEffectiveUser().getEmail();
if (form_data.Document_Type == "Text2"){
var dumpfolder = DriveApp.getFolderById("12345")
var templateSheet = DriveApp.getFileById("67890");
var Newform2= templateSheet.makeCopy(title+ " "+now,dumpfolder);
var qs = SpreadsheetApp.open(Newform2);
var dropSheet = qs.getSheetByName("blank");
var URL3 = Newform2.getUrl();
dropSheet.getRange("i8").setValue(title);
dropSheet.getRange("bc5").setValue(now);
dropSheet.getRange("b5").setValue(platform);
dropSheet.getRange("p5").setValue(area);
dropSheet.getRange("x5").setValue(rota);
dropSheet.getRange("al5").setValue(works);
dropSheet.getRange("at6").setValue(name);
NewOPLPOA.setSharing(DriveApp.Access.DOMAIN,DriveApp.Permission.COMMENT);
NewOPLPOA.setOwner("ME");
sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL3]);
GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL3);
ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
" + URL3, ui.ButtonSet.OK);
}
else if (form_data.Document_Type == "Text1"){
var dumpfolder = DriveApp.getFolderById("abcd")
var templateSheet = DriveApp.getFileById("bgtrd");
var Newform1 = templateSheet.makeCopy(title+ " "+now,dumpfolder);
var qs = SpreadsheetApp.open(Newform1);
var dropSheet = qs.getSheetByName("DOC1");
var URL4 = Newform1.getUrl();
dropSheet.getRange("aa3").setValue(platform);
dropSheet.getRange("ah3").setValue(area);
dropSheet.getRange("ao3").setValue(works);
NewSEWO.setSharing(DriveApp.Access.DOMAIN, DriveApp.Permission.COMMENT);
NewSEWO.setOwner("Me");
sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL4]);
GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL4);
ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
" + URL4, ui.ButtonSet.OK);
}
else{
ui.alert("Error, Please try again, make sure you are listing all required information.");
}
}
--HTML--
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body>
<form id="myform">
<div class="form-group">
<label for="Document_Type">Document Type</label>
<select class="form-control" id="Document_Type" name = "Document_Type" required="required">
<?
var SS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Set Up");
var Avals = SS.getRange("A2:A").getValues();
var numberOfValues = Avals.filter(String).length;
var RangeVals = SS.getRange(2,1,numberOfValues).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeVals.length; ++i) { ?>
<option><?!= RangeVals[i] ?></option>
<? } ?>
</select>
</div>
<div class="form-group">
<label for ="Name">Your Name</label>
<select class="form-control" name='Name' id="Name" required="required">
<?
var AvalN = SS.getRange("E2:E").getValues();
var numberOfValuesN = AvalN.filter(String).length;
var RangeValsN = SS.getRange(2,5,numberOfValuesN).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsN.length; ++i) { ?>
<option><?!= RangeValsN[i] ?></option>
<? } ?>
</select>
</div>
<div class="form-group">
<label for="Platform">Platform</label>
<select class="form-control" id="Platform" name = "Platform" required="required">
<?
var AvalP = SS.getRange("C2:C").getValues();
var numberOfValuesP = AvalP.filter(String).length;
var RangeValsP = SS.getRange(2,3,numberOfValuesP).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsP.length; ++i) { ?>
<option><?!= RangeValsP[i] ?></option>
<? } ?>
</select>
</div>
<div class="form-group">
<label for="Area">Area</label>
<select class="form-control" id="Area" name = "Area" required="required">
<?
var AvalA = SS.getRange("D2:D").getValues();
var numberOfValuesA = AvalA.filter(String).length;
var RangeValsA = SS.getRange(2,4,numberOfValuesA).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsA.length; ++i) { ?>
<option><?!= RangeValsA[i] ?></option>
<? } ?>
</select>
</div>
<div class="block form-group">
<label for="Rotation">Rotation</label>
<select class="form-control" name='Rotation' id="Rotation">
<?
var AvalR = SS.getRange("F2:F").getValues();
var numberOfValuesR = AvalR.filter(String).length;
var RangeValsR = SS.getRange(2,6,numberOfValuesR).getValues();
?>
<option disabled selected value> -- select an option -- </option>
<? for (var i = 0; i < RangeValsR.length; ++i) { ?>
<option><?!= RangeValsR[i] ?></option>
<? } ?>
</select>
</div>
<div class="block form-group">
<label for="WorkSt">Work Station</label>
<input type='text' name='WorkSt' id="WorkSt" />
</div>
<div class="block form-group">
<label for="Title">Title</label>
<input type='text' name='Title' id="Title" required="required"/>
</div>
<div class="block">
<button type="submit" class="action">Submit</button>
</div>
</form>
<script>
document.querySelector("#myform").addEventListener("submit",
function(e)
{
e.preventDefault(); //stop form from submitting
google.script.run.addNewItem(this);
google.script.host.close();//close this dialogbox
}
);
</script>
</body>
</html>
is there a way to have each if statement its own function?
For visibility purposes, you certainly can modify your code as
function addNewItem(form_data)//pulls data from form
{
var ui = SpreadsheetApp.getUi();
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var n = new Date();
var now = ((n.getMonth()+1) + "/" + n.getDate() + "/" + n.getFullYear());
var doctyp = form_data.Document_Type;
var name = form_data.Name;
var title = form_data.Title;
var platform = form_data.Platform;
var area = form_data.Area;
var rota = form_data.Rotation;
var works = form_data.WorkSt;
var recipient = Session.getEffectiveUser().getEmail();
if (form_data.Document_Type == "Text2"){
function1();
}
else if (form_data.Document_Type == "Text1"){
function2();
}
else{
ui.alert("Error, Please try again, make sure you are listing all required information.");
}
function function1(){
var dumpfolder = DriveApp.getFolderById("12345")
var templateSheet = DriveApp.getFileById("67890");
...
}
function function2(){
var dumpfolder = DriveApp.getFolderById("abcd")
...
}
Would this even help the speed?
Not really. To help up speed, you should rather try to implement Best Practices.
In particular: Reduce repeated calls to external services, including SpreadsheetApp.
For example, try to position the cells to which you want to assign values into an adjacent range, so you can use the method setValues() instead of multiple setValue() and thus make your code more efficient.
Sample:
var range = dropSheet.getRange("I8:N8");
var values = [];
values[0] = [];
values[0].push(title, now, platform, area, rota, works, name);
range.setValues(values);
Also, try to avoid repeating the same request for each if condition and rather make a single request after exiting the if statement, e.g. for:
sheet.appendRow([now,doctyp,name,title,platform,area,rota,works,URL3]);
GmailApp.sendEmail(recipient, title+ " has been created.", "Your document has been created." +'\n'+ "Here is the link to your copy! Link: " + URL3);
ui.alert("Email Sent", "An email has been sent with your documents link. You can also use the below link to view the document now, click ctrl C to copy. \
" + URL3, ui.ButtonSet.OK);
I hope this helps!

Issue In joomla custom dropdown list development

For the past 3 days, I've been stuck on a dropdown list development using joomla 2.5, I have to retrieve data from database and show this data in a drop down the steps I followed are mentioned below:
Inside the models folder I have created a new model inside fields folder and name this file "fieldname.php"
Now the file "Models/fields/fieldname.php" contains following source code:
<?php
defined('JPATH_BASE') or die;
jimport('joomla.html.html');
jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldMyCompany extends JFormFieldList
{
protected $type = 'MyCompany';
public function getOptions()
{
// Initialize variables.
$options = array();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id As value,name As text');
$query->from('#_k2_tags AS a');
$query->order('a.name');
$db = $this->getDbo();
// Get the options.
$db->setQuery($query);
$options = $db->loadObjectList();
// Check for a database error.
if ($db->getErrorNum()) {
JError::raiseWarning(500, $db->getErrorMsg());
}
print_r($options);exit;
return $options;
}
}
after that inside my model filter.php I added the following code.
Models/filter.php:
<?php
defined( '_JEXEC' ) or die;
jimport('joomla.application.component.modeladmin');
class FiltersModelFilter extends JModelAdmin
{
//Add this handy array with database fields to search in
protected $searchInFields = array('text','a.name');
//Override construct to allow filtering and ordering on our fields
public function __construct($config = array()) {
$config['filter_fields']=array_merge($this->searchInFields,array('a.name'));
parent::__construct($config);
}
public function getTable($type = 'Filter', $prefix = 'FiltersTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
protected function loadFormData()
{
$data = JFactory::getApplication()->getUserState('com_filters.edit.filter.data', array());
if (empty($data)) {
$data = $this->getItem();
}
return $data;
}
public function getForm($data = array(), $loadData = true)
{
$form = $this->loadForm('com_filters.filter', 'filter', array('control' => 'jform', 'load_data' => $loadData));
return $form;
}
protected function getListQuery(){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
//CHANGE THIS QUERY AS YOU NEED...
$query->select('id As value, name As text')
->from('#_k2_tags AS a');
// Filter search // Extra: Search more than one fields and for multiple words
$regex = str_replace(' ', '|', $this->getState('filter.search'));
if (!empty($regex)) {
$regex=' REGEXP '.$db->quote($regex);
$query->where('('.implode($regex.' OR ',$this->searchInFields).$regex.')');
}
// Filter company
$company= $db->escape($this->getState('filter.name'));
if (!empty($company)) {
$query->where('(a.name='.$company.')');
}
// Filter by state (published, trashed, etc.)
$state = $db->escape($this->getState('filter.state'));
if (is_numeric($state)) {
$query->where('a.published = ' . (int) $state);
}
elseif ($state === '') {
$query->where('(a.published = 0 OR a.published = 1)');
}
//echo $db->replacePrefix( (string) $query );//debug
return $query;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* #since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication('administrator');
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
//Omit double (white-)spaces and set state
$this->setState('filter.search', preg_replace('/\s+/',' ', $search));
//Filter (dropdown) state
$state = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_state', '', 'string');
$this->setState('filter.state', $state);
//Filter (dropdown) company
$state = $this->getUserStateFromRequest($this->context.'.filter.name', 'filter_company', '', 'string');
$this->setState('filter.name', $state);
//Takes care of states: list. limit / start / ordering / direction
parent::populateState('a.name', 'asc');
}
}
Inside the "Views/filter/view.html.php"
<?php
defined( '_JEXEC' ) or die;
jimport( 'joomla.application.component.view');
class FiltersViewFilter extends JView
{
protected $item;
protected $form;
protected $state;
protected $sortColumn;
protected $sortDirection;
protected $searchterms;
public function display($tpl = null)
{
$this->item = $this->get('Item');
$this->state = $this->get('State');
$this->form = $this->get('Form');
$this->state= $this->get('State');
//Following variables used more than once
$this->sortColumn = $this->state->get('list.ordering');
$this->sortDirection= $this->state->get('list.direction');
$this->searchterms= $this->state->get('filter.search');
$this->addToolbar();
parent::display($tpl);
}
public function addToolbar()
{
if ($this->item->ID) {
JToolBarHelper::title(JText::_('Filter Title'));
} else {
JToolBarHelper::title(JText::_('Add Filter Title'));
}
JToolBarHelper::apply('filter.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::save('filter.save', 'JTOOLBAR_SAVE');
JToolBarHelper::save2new('filter.save2new', 'JTOOLBAR_SAVE_AND_NEW');
JToolBarHelper::cancel('filter.cancel');
}
}
inside the views/filter/tmpl/default.php
<?php defined( '_JEXEC' ) or die;
//Get companie options
JFormHelper::addFieldPath(JPATH_COMPONENT . '/models/fields');
$companies = JFormHelper::loadFieldType('MyCompany', false);
$companyOptions=$companies->getOptions(); // works only if you set your field getOptions on public!!
//Get companie options
?>
<form action="index.php?option=com_filters&ID=<?php echo $this->item->ID ?>"
method="post" name="adminForm" class="form-validate">
<fieldset id="filter-bar">
<div class="filter-search fltlft">
<input type="text" name="filter_search" id="filter_search" value="<?php echo $this->escape($this->searchterms); ?>" title="<?php echo JText::_('Search in Names, etc.'); ?>" />
<button type="submit">
<?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?>
</button>
<button type="button" onclick="document.id('filter_search').value='';this.form.submit();">
<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>
</button>
</div>
<div class="filter-select fltrt">
<select name="filter_state" class="inputbox" onchange="this.form.submit()">
<option value="">
<?php echo JText::_('JOPTION_SELECT_PUBLISHED');?>
</option>
<?php echo JHtml::_('select.options', JHtml::_('jgrid.publishedOptions', array('archived'=>false)), 'value', 'text', $this->state->get('filter.published'), true);?>
</select>
<select name="filter_type" class="inputbox" onchange="this.form.submit()">
<option value=""> - Select Company - </option>
<?php echo JHtml::_('select.options', $companyOptions, 'value', 'text', $this->state->get('filter.name'));?>
</select>
</div>
</fieldset>
<div class="width-60 fltlft">
<fieldset class="adminform">
<ul class="adminformlist">
<?php foreach ($this->form->getFieldset() as $field): ?>
<li><?php echo $field->label; ?>
<?php echo $field->input; ?></li>
<?php endforeach ?>
</ul>
</fieldset>
</div>
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</form>
Please help me in identification of my error I need to sort out issue as soon as possible.
change this Models/fields/fieldname.php to Models/fields/mycompany.php
also change from JFormFieldMyCompany to JFormFieldMycompany
and protected $type = 'MyCompany'; to protected $type = 'mycompany';

Facebook OAuth no longer functioning

I had a script that was working perfectly up until a couple of hours ago. This script authorizes a user, checks to see if the user is logged in, and inserts data into my database.
As of now, it fails to both identify a user or insert any data. Any help will be appreciated.
<style type="text/css">
<!--
#apDiv1 {
position:absolute;
width:200px;
height:198px;
z-index:1;
left: 757px;
top: 18px;
}
-->
</style>
<div id="apDiv1"><img src="../Downloads/tree06_small.png" width="188" height="250" alt="" /></div>
<?php
require ("santatree/facebook.php");
include('login.php');
$facebook = new Facebook(array(
'appId' => 'id',
'secret' => 'secret',
));
$db_select=mysql_select_db($db_database);
if (!$db_select)
{
die ("Impossible Function". mysql_error());
}
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
if ($user) {
$token = $facebook->getAccessToken();
$friends = $facebook->api('/me/friends');
$friendsData = $friends['data'];
$User = $user['data'];
for ($i = 0; $i < sizeof($friendsData); $i++)
{
$friend = $friendsData[$i];
echo $friend['name'] . ", ";
echo $friend['id'];
echo $user['id'];
$sq1 = "INSERT into tbl_Friends (Name, FriendID, Access_ID) VALUES ('".$friend['name']."', '" .$friend['id']."', '".$user_profile['id']."')";
error_log($e);
$user = null;
}
}
mysql_query($sq1);
}
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
$access_token = $_SESSION['fb_276853929000834_access_token'];
if (!$access_token) {
echo '<script>';
echo 'top.location.href = "'.$loginUrl.'";';
echo '</script>';
} else {
// ------ Create Drop Down Name List from Friends Table ------
$myuserid = $user_profile['id'];
echo "<html>";
echo "<form enctype='multipart/form-data' method='post' action='uploadpicture1.php' name='Giftgiver'>";
$result= #mysql_query("select Friend_ID, tbl_Friends.Name from tbl_Friends inner join tbl_Users on tbl_Friends.Access_ID=tbl_Users.Access_ID where tbl_Friends.Access_ID = $myuserid");
print "<p> Select a Friend: \n";
print "<Select name=\"Friend_ID\">\n";
while ($row=mysql_fetch_assoc($result)){
$Friend_ID=$row['Friend_ID'];
$Name =$row['Name'];
print "<option value=$Friend_ID>$Name \n";
}
print "</select>\n";
print "</p>\n";
echo "Choose a gift!";
echo "<input type='file' name='GiftChoice' value='1'>";
}
echo "</form>";
echo "</html>";
?>
Have you checked to make you you have updated to Facebook's oAuth 2.0?
All FB apps and apps using the FB api are required to upgrade to oAuth 2.0 by October 1st, 2011.