Google Sheets QR code "tab" - google-sheets

I am working with the Google sheets to make QR codes. I have my scanner programmed to do a 'TAB' function after every scan and it works well. I would like to make a single QR code that has 3 different pieces of information in it with a tab between each and an enter on the end. I have tried many ways and just found that most of them work fine in something like Notepad, but nothing is working in a form where there are 3 fields. The form has the following fields: Plant, Department, Part#
I have tried using:
//cell E12 has 106+%09+W6311A+%09+12345678 or 106+char(9)+W6311A+char(9)+12345678
=if(isblank(E12),"",image("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl="&E12))
//A14==106, B14==W06311A, C14==12345678
=CONCATENATE(A14, char(9),B14,char(9),C14,char(10))
//A15==the above concatenate code
=image("https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl="& urlencode(join(char(10),arrayformula(A15))))
//this script is called by the above code:
/**
* Converts a string to a properly encoded URI
*
* #param {string} component The component you want to encode
* #return {string} The encoded URI component.
* #customfunction
*/
function urlencode ( component ) {
if ( component && component.map ) {
return component.map ( urlencode );
Logger.log(component);
}
else {
return encodeURIComponent ( component || "" ) ;
Logger.log("2 "+component);
}
}
As I said, they work fine in word or notepad, but they put all the information into one field of a form. One scan could be quicker then the current 3 individual scans that we do. Is there a coding method that is specific to fill in forms?
Thanks,
Josh

Related

How to check whether url used in IMAGE formula was correct and image is displayed?

I have a list of images I reference using their filenames:
=image("domainname.com/somepath/"&A2&".jpg")
where in A2 is a filename.
Unfortunately some of these images have .png extension.
I try to find a solution to check if file with jpg extension is correct and image is found. If not found I want to use
=image("domainname.com/somepath/"&a2&".png")
For this cell.
IFNA and IFERROR formulas do not work.
I tried also to concatenate formulas:
=image("domainname.com/somepath/"&a2&".png")&image("domainname.com/somepath/"&a2&".jpg")
but I see that you can use & only for strings
There are thousands of images in different folders for reference and I cannot control their format.
Do you have any idea?
One workaround I would suggest is to create and use a custom function to validate the image URL.
Custom Functions
Google Sheets offers hundreds of built-in functions like AVERAGE, SUM, and VLOOKUP. When these aren’t enough for your needs, you can use Google Apps Script to write custom functions — say, to convert meters to miles or fetch live content from the Internet — then use them in Google Sheets just like a built-in function.
Sample Custom Function:
/**
* validate image
*
* #param {input} image url to validate.
*
* #customfunction
*/
function IMAGE_TRY(input) {
try{
var response = UrlFetchApp.fetch(input);
return 1;
} catch(err) {
return 0;
}
}
This custom function will take 1 image URL argument and verify if that URL is valid using the try-catch method. The function will return 1 when the URL is valid and 0 if not a valid URL
Note that the #customfunction tag is important in the function comment so that this custom function will appear as a suggested formula when you are typing in a cell.
Once you have created a custom function, you can use this to validate the URL and use the correct image URL using IF function.
Sample:
=IF(IMAGE_TRY("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.jpg"),image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.jpg"), image("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp.png"))
Sample Output:
(UPDATE)
OPTIMIZED SOLUTION:
Sample Custom Function:
/**
* get image url with correct file extension.
*
* #param {input} image url string without extension.
*
* #customfunction
*/
function getURL(input) {
try{
var response = UrlFetchApp.fetch(input+".jpg");
return (input.concat(".jpg"));
} catch(err) {
return (input.concat(".png"));
}
}
This solution accepts an image URL without file extension and return an image URL with the valid file extension.
Sheets Formula:
=image(getURL("https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_160x56dp"))

Doxygen anchor inside function

I have a filter which converts actual code into #code/#endcode blocks but I can't figure out a way to create a #ref link to these sections.
Here's a snippet of what I mean:
/**
* Refer to this example: #ref example1
* #param $arg1
* #param $arg2
*/
public function somefunction($arg1, $arg2)
{
/**
* #anchor example1 #code
if (true)
{
$this = 'bollox';
}
* #endcode
**/
}
The output of this looks pretty much like what I want (although I haven't decided on how best to truly indicate the link point...exmple1 springs to mind).
The problem is that the hyperlink for example1 links to the filename.html#example1.
I've checked the source and there is an anchor class being generated.
I understand I'm not really using anchor as documented.
Any suggestions welcome.
Note: I'm not specifically trying to get anchor to work...just want a hyperlink/bookmark to link a \ref (or similar).

how to validate and check if a entered URL is valid or not in Drupal 6

Without using any third party modules, is it possible to validate and check at the same time if any URL entered in a text-box is valid or not in Drupal 6 ? Some sample code will be appreciated.
menu_valid_path() function in menu.inc (which is part of Drupal Core) does just that.
To answer your specific question:
Without using any third party modules, is it possible to validate and check at the same time if any URL entered in a text-box is valid or not in Drupal 6
Yes.
You will, however, need to create a simple custom module.
Let's assume:
Your form id is my_form_1
The field name in question is my_path_field_1
In your MODULENAME.module file:
<?php
/**
* Modifies the existing form element 'my_path_field_1' to add
* 'MODULENAME_path_validate' function to validation array.
*
* (MYMODULE_path_validate is defined below)
*/
function MODULENAME_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'my_form_1' :
$form['my_path_field_1']['#element_validate'] = array('MODULENAME_path_validate');
break;
}
// Note, you could use hook_form_FORM_ID_alter(&$form, &$form_state)
// instead of the above to simplify things if the only thing this module
// does is validite one field for a valid path.
/**
* Validates the my_path_field_1 using Drupal's built-in menu_valid_path()
* function. Returns a form error if the field does not contain a valid path
* or the current user does not have access to the path's permission.
*/
function MODULENAME_path_validate($element, &$form_state) {
if (!menu_valid_path($element)) {
form_error($element, t('The path entered does not exist or you do not have permission to access it.'));
}
}

jQuery autocomplete not displaying my encoded values

I am working from this example: http://jqueryui.com/demos/autocomplete/#remote and I am encoding the output like this:
$rows = array();
while($r = mysql_fetch_assoc($category_result))
{
$rows[] = $r;
error_log ("rows: ".$rows[0]);
}
echo json_encode($rows);
But the dropdown on the other side shows nothing. Here is my test page: http://problemio.com/test.php - if you enter "ho" it matches 2 results in the database, but they are not getting displayed for some reason. Any idea why?
Thanks!!
The properties should be named label and value. From the JQuery UI demo page you linked to:
The local data can be a simple Array of Strings, or it contains
Objects for each item in the array, with either a label or value
property or both. The label property is displayed in the suggestion
menu.
So you would need to rename category_name to label either in PHP or later on in your JavaScript source handler function. The latter would require you to replace the PHP URL with a callback function like in the remote example. That way you could get the data any way you want (e.g. by jQuery.getJSON()) and work with it before it gets handed over to the suggestion box.
Hope this helps.
Regarding your comment, this should do it:
$rows = array();
while ($r = mysql_fetch_array($category_result)) {
$rows[] = array("label" => $r["category_name"]);
}
echo json_encode($rows);

Get fragment (value after hash '#') from a URL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can i select the fragment after the '#' symbol in my URL using PHP?
The result that i want is "photo45".
This is an example URL:
http://example.com/site/gallery/1#photo45
If you want to get the value after the hash mark or anchor as shown in a user's browser: This isn't possible with "standard" HTTP as this value is never sent to the server (hence it won't be available in $_SERVER["REQUEST_URI"] or similar predefined variables). You would need some sort of JavaScript magic on the client side, e.g. to include this value as a POST parameter.
If it's only about parsing a known URL from whatever source, the answer by mck89 is perfectly fine though.
That part is called "fragment" and you can get it in this way:
$url=parse_url("http://example.com/site/gallery/1#photo45 ");
echo $url["fragment"]; //This variable contains the fragment
A) already have url with #hash in PHP? Easy! Just parse it out !
if( strpos( $url, "#" ) === false ) echo "NO HASH !";
else echo "HASH IS: #".explode( "#", $url )[1]; // arrays are indexed from 0
Or in "old" PHP you must pre-store the exploded to access the array:
$exploded_url = explode( "#", $url ); $exploded_url[1];
B) You want to get a #hash by sending a form to PHP?     => Use some JavaScript MAGIC! (To pre-process the form)
var forms = document.getElementsByTagName('form'); //get all forms on the site
for (var i = 0; i < forms.length; i++) { //to each form...
forms[i].addEventListener( // add a "listener"
'submit', // for an on-submit "event"
function () { //add a submit pre-processing function:
var input_name = "fragment"; // name form will use to send the fragment
// Try search whether we already done this or not
// in current form, find every <input ... name="fragment" ...>
var hiddens = form.querySelectorAll('[name="' + input_name + '"]');
if (hiddens.length < 1) { // if not there yet
//create an extra input element
var hidden = document.createElement("input");
//set it to hidden so it doesn't break view
hidden.setAttribute('type', 'hidden');
//set a name to get by it in PHP
hidden.setAttribute('name', input_name);
this.appendChild(hidden); //append it to the current form
} else {
var hidden = hiddens[0]; // use an existing one if already there
}
//set a value of #HASH - EVERY TIME, so we get the MOST RECENT #hash :)
hidden.setAttribute('value', window.location.hash);
}
);
}
Depending on your form's method attribute you get this hash in PHP by:
$_GET['fragment'] or $_POST['fragment']
Possible returns: 1. ""[empty string] (no hash) 2. whole hash INCLUDING the #[hash] sign (because we've used the window.location.hash in JavaScript which just works that way :) )
C) You want to get the #hash in PHP JUST from requested URL?
                                    YOU CAN'T !
...(not while considering regular HTTP requests)...
...Hope this helped :)
I've been searching for a workaround for this for a bit - and the only thing I have found is to use URL rewrites to read the "anchor". I found in the apache docs here http://httpd.apache.org/docs/2.2/rewrite/advanced.html the following...
By default, redirecting to an HTML anchor doesn't work, because mod_rewrite escapes the # character, turning it into %23.
This, in turn, breaks the redirection.
Solution: Use the [NE] flag on the RewriteRule. NE stands for No
Escape.
Discussion: This technique will of course also work with other special
characters that mod_rewrite, by default, URL-encodes.
It may have other caveats and what not ... but I think that at least doing something with the # on the server is possible.
You can't get the text after the hash mark. It is not sent to the server in a request.
I found this trick if you insist want the value with PHP.
split the anchor (#) value and get it with JavaScript, then store as cookie, after that get the cookie value with PHP
If you are wanting to dynamically grab the hash from URL, this should work:
https://stackoverflow.com/a/57368072/2062851
<script>
var hash = window.location.hash, //get the hash from url
cleanhash = hash.replace("#", ""); //remove the #
//alert(cleanhash);
</script>
<?php
$hash = "<script>document.writeln(cleanhash);</script>";
echo $hash;
?>
You can do it by a combination of javascript and php:
<div id="cont"></div>
And by the other side;
<script>
var h = window.location.hash;
var h1 = (win.substr(1));//string with no #
var q1 = '<input type="text" id="hash" name="hash" value="'+h1+'">';
setInterval(function(){
if(win1!="")
{
document.querySelector('#cont').innerHTML = q1;
} else alert("Something went wrong")
},1000);
</script>
Then, on form submit you can retrieve the value via $_POST['hash'] (set the form)
You need to parse the url first, so it goes like this:
$url = "https://www.example.com/profile#picture";
$fragment = parse_url($url,PHP_URL_FRAGMENT); //this variable holds the value - 'picture'
If you need to parse the actual url of the current browser, you need to request to call the server.
$url = $_SERVER["REQUEST_URI"];
$fragment = parse_url($url,PHP_URL_FRAGMENT); //this variable holds the value - 'picture'
Getting the data after the hashmark in a query string is simple. Here is an example used for when a client accesses a glossary of terms from a book. It takes the name anchor delivered (#tesla), and delivers the client to that term and highlights the term and its description in blue so its easy to see.
setup your strings with a div id, so the name anchor goes where its supposed to and the JavaScript can change the text colors
<div id="tesla">Tesla</div>
<div id="tesla1">An energy company</div>
Use JavaScript to do the heavy work, on the server side, inserted in your PHP page, or wherever..
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
I am launching the Java function automatically when the page is loaded.
<script>
$( document ).ready(function() {
get the anchor (#tesla) from the URL received by the server
var myhash1 = $(location).attr('hash'); //myhash1 == #tesla
trim the hash sign off of it
myhash1 = myhash1.substr(1) //myhash1 == tesla
I need to highlight the term and the description so I create a new var
var myhash2 = '1';
myhash2 = myhash1.concat(myhash2); //myhash2 == tesla1
Now I can manipulate the text color for the term and description
var elem = document.getElementById(myhash1);
elem.style.color = 'blue';
elem = document.getElementById(myhash2);
elem.style.color = 'blue';
});
</script>
This works. client clicks link on client side (example.com#tesla) and goes right to the term. the term and the description are highlighted in blue by JavaScript for quick reading .. all other entries left in black..

Resources