Special charactes in query parameter - character-encoding

I am using 1 search option on my form. Here when i pass any special
characters like & or $ it does not hold that request parameter in the search box yeah but it is processing my request of search.

You need to URL encode the values in the query string.

I don't know Java but I used code similar to that below when sending user text to Google translate via Google URL parameter. (Assume values for myText, myURL, and myTextURL are already assigned.)
<script>
function transfix(isURL,form) {
if(isURL) window.open( myURL + encodeURIComponent(myText) );
else window.open( myTextURL + decodeURIComponent(myText) );
}
</script>
<form target=_blank id="translate" name="translate">
<input type="button" value="Text" onclick="transfix(false,this.form)">
<input type="button" value="URL" onclick="transfix(true,this.form)">
</form>

Related

Is there a way to get a QR code image with Google Apps Script using the POST method of the Google Charts API?

I am using a Google Script to generate tickets to an event, and the ticket includes a QR code which goes to a pre-filled Google Form link. Since it's pre-filled, the string is quite long, and the Google Charts API for creating QR codes will not accept a string of text that long using a GET request, but I can't find any documentation of how to code the POST request into Apps Script. How do I generate a POST request in Apps Script that will return an image of the QR code which I can then insert into the document?
I already tried the GET request, and it truncates the URL before encoding it into a QR code. That gets me to the Google Form, but not the pre-filled version that the link generates (actually pretty smart on Google's part to have it truncate the string in a place that still gives a usable URL, but that's for another day...)
I have also tried the HtmlService to render the QR code using the POST method with the Charts API in an HTML form that automatically submits on the loading of that HTML. If I use showSidebar(), this will open the image in a new tab, but I haven't figured out how to return that image so that it can be inserted into the document.
I've also tried creating a blob with the HTML and then saving the blob as a PNG, but from the research I've done, the .getAs() method doesn't render images when converting the HTML.
The renderQR function:
function renderQR(inputUrl) {
var html = HtmlService.createTemplateFromFile('QREncode.html');
html.url = inputUrl;
var rendered = html.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setHeight(300)
.setWidth(300);
return rendered;
}
The QREncode.html file:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script type='application/javascript'>
// Send the POST when the page is loaded,
// which will replace this whole page with the retrieved chart.
function loadGraph() {
var frm = document.getElementById('post_form');
if (frm) {
frm.submit();
}
}
</script>
</head>
<body onload="loadGraph()">
<form action='https://chart.googleapis.com/chart' method='POST' id='post_form'>
<input type='hidden' name='cht' value='qr' />
<input type='hidden' name='chl' value='<?= url ?>' />
<input type='hidden' name='chs' value='300x300' />
<input type='submit'/>
</form>
</body>
</html>
When I treat the return from the renderQR() function as an image, Apps script gives an error saying that it is "Invalid image data", which makes sense -- but how do I convert it into an image, or is there a better or simpler way I could be doing this?
You need to get the qr code in the Apps Script, not in the browser:
var imageData = UrlFetchApp.fetch('https://chart.googleapis.com/chart', {
'method' : 'post',
'payload' : {
'cht': 'qr',
'chl': 'https://google.com',
'chs': '300x300'
}}).getContent();
For those looking for a formula solution (without Apps Script)
Reference: https://www.benlcollins.com/spreadsheets/qr-codes-in-google-sheets/
Solution:
=IMAGE("https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl="&ENCODEURL(A1))

Extracting authenticity token for login using JMeter

<input name="authenticity_token" type="hidden" value="sn0fmV699N6hHzljhZPqzk+WSaRh9WPspQ5fa/dd6nA=">
I want to extract sn0fmV699N6hHzljhZPqzk+WSaRh9WPspQ5fa/dd6nA= from the above HTML.
I tried using input name="authenticity_token" type="hidden" value="(.*?)"/> but it doesn't return anything. can someone pls help on it ??
Assuming that you are getting above Token in response to one of your request. So identify that request and add PostProcessor>Regular Expression Extractor under it. Use following values in it.
Reference Name: ExtractedToken
Regular Expression: <input name="authenticity_token" type="hidden" value="(.+?)" /></div>
Template: $1$
Match No: 1
Default Value: Token Error
Add a debug sampler in your Test Plan, this will help you see if anything is being stored in variable named "ExtractedToken". If you see your expected value in this variable that means Regular Expression extractor is working fine.
Now you can use this variable in all those requests where token value will be required.
Reg Expression Example: https://docs.blazemeter.com/customer/portal/articles/1743642
Login Example: https://docs.blazemeter.com/customer/portal/articles/1743663-how-to-use-jmeter-for-login-authentication-

How can I do a multipart Post in Dart / AngularDart

I've got a REST api which assumes a multipartfile in the a post method.
Is there any way to do this kind of posts in Dart / AngularDart because all the solutions I've found so far are not working.
I've tried to use the http://dart-gde.github.io/dart-google-oauth2-library/multipart_file/MultipartFile.html solution, but it is not working in the browser because dart.io is not supported there.
My question is about the client side part directly from the browser. The serverside, which is written in Java can handle the post.
If you need multipart for file upload, all you have to do is send a FormData object using the HttpRequest class. Example:
import "dart:html";
...
var fileData; //file data to be uploaded
var formData = new FormData();
formData.append("field", "value"); //normal form field
formData.appendBlob("data", fileData); //binary data
HttpRequest.request("/service-url", method: "POST", sendData: formData).then((req) {
...
});
Furthermore, if you need to allow the user to upload a file from his hard disk, you have to use a html form with an <input type="file"> tag. Example:
Html file:
<form id="myForm" action="/service-url" method="POST" enctype="multipart/form-data">
<input type="text" name="field"> <!-- normal field -->
<input type="file" name="fileData"> <!-- file field -->
</form>
dart file:
var formData = new FormData(querySelector("#myForm"));
HttpRequest.request("/service-url", method: "POST", sendData: formData).then((req) {
...
});
I know this was asked a long time ago, but I've just had the same problem and the fix for me is the following (based on luizmineo's answer):
Use formData.appendBlob("data", fileData);
Don't set an explicit Content-Type header. This will get Dart to calculate the boundary section of the form-data which is crucial.
I finally found a way to post it as a multi-part form:
void uploadFiles() {
var formData = new FormData(querySelector("#fileForm"));
HttpRequest.request("/sp/file", method: "POST", sendData: formData).then((req) {
print("OK");
});
}
is used in conjunction with
<form id="fileForm" action="/sp/file" method="POST">
<input type="file" #upload (change)="uploadFiles(upload.files)"
(dragenter)="upload.style.setProperty('border', '3px solid green')"
(drop)="upload.style.setProperty('border', '2px dotted gray')" class="uploadDropZone" name="toUpload"/>

How to use NSUserDefaults in phonegap?

I am new to this iOS/phonegap technology.
I am working on an iPhone/iOS app using phonegap. It has a login page with two text fields "Username" & "Password".
<input type="text" class="form-control input-lg user_name" id="txtUserName" placeholder="Username" />
<input type="password" class="form-control input-lg pass_word" id="txtPassword" placeholder="Password" />
<button id="btnLogin" class="large color blue button login_top btn-block" type="submit" value="Login">Login</button>
On $(document).ready(function() Login processing is carried out.
Now I want to save email address of the user. i.e When I logged out it should remember the email address so it doesn't have to be input again.
I am developing this using phonegap. I went through many links and found out that this can be done using
1. NSUserDefaults
2. KeyChain
I am thinking of using NSUserDefaults, but am not understanding how to implement this thing.
i.e Since this is native c code we have to write in the appDelegate.m file. Am I right?
And then how to link this code to my login page?
Can anyone please send me the full code to implement this functionality.
I mean the code that i need to add in appdelegate and linking that code to my login page.
If you or someone else needs it,
There is a cordova plugin for that:
https://github.com/apla/me.apla.cordova.app-preferences/
cordova plugin add me.apla.cordova.app-preferences
Example from it's site:
var prefs = plugins.appPreferences;
// store key => value pair
prefs.store (ok, fail, 'key', 'value');
// store key => value pair in dict (see notes)
prefs.store (ok, fail, 'dict', 'key', 'value');
// fetch value by key (value will be delivered through "ok" callback)
prefs.fetch (ok, fail, 'key');
// fetch value by key from dict (see notes)
prefs.fetch (ok, fail, 'dict', 'key');

How do you post form submissions to a Google Drive Spreadsheet using Google App Scripts

I want to create a form on my site that when a user submits, it posts their data to a particular Spreadsheet in my Google Drive. How can I do this with Google App Scripts?
sample form
<form method='post' action='https://script.google.com/macros/s/xxxx.....'>
Favorite Color <input type='text' value='' name='color' />
Favorite Ice Cream Flavor <input type='text' value='' name='flavor' />
<input type='button' value='submit' />
</form>
so that when I hit submit it creates a record in a Google Drive Spreadsheet
| color | flavor |
red vanilla
Is this doable with GAS, or is sort of task more suited for the Google Drive SDK (via Javascript)?
UPDATE
Used the example from How to add form elements to UI App Service to complete the script
This is the current script I've thrown together... and it works!!!
var SPREADSHEET_ID = '0Aqa6DbU_0sv7dGNrMEEybjNrdm00MlpwTTNx...';
function doPost(e) {
var app = UiApp.getActiveApplication();
SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName('RequestInvites').appendRow([e.parameter.emailAddress, 'hash123']);
app.add(app.createLabel("Form submitted. Your email address is: '" + e.parameter.emailAddress));
return app;
}
function createForm(e){
var app = UiApp.createApplication();
var form = app.createFormPanel();
var flow = app.createFlowPanel();
flow.add(app.createLabel('Enter your email address to get an invitation').setId('inviteLabel'));
flow.add(app.createTextBox().setId('emailAddress').setName('emailAddress'));
flow.add(app.createSubmitButton("Request Invite"));
form.add(flow);
app.add(form);
return app;
}
You can do that with GAS. In your script, use function doPost(e) to retrieve user inputs when the submit button (that you might have forgotten ;) is cliked.
In the doPost function, you can access inputs with their 'name' attribute like that : e.parameter.color and e.parameter.flavor.
Then, you can use Spreadsheet service to write in your spreadsheet. Documentation for this service is here. So you open your spreadsheet, and add a row in the correct sheet like that : SpreadsheetApp.openById('id of your spreadsheet').getSheetByName('colors_and_flavors').appendRow([e.parameter.color, e.parameter.flavor]);.
Let's recap :
function doPost(e) {
SpreadsheetApp.openById('id of your spreadsheet').getSheetByName('colors_and_flavors').appendRow([e.parameter.color, e.parameter.flavor]);
}
Hope it helps ! ;)

Resources