Using url parameters in golang template code - go

I'm new to Go and trying to modify some code written by someone else. Right now he tests the stored value of a given day to determine if someone took lunch that day or not.
What I want to do is see if there's a stored value and if there isn't, use the default value which is passed via URL parameter. The code looks like this:
<input id="lunch{{.place}}" type="checkbox" {{if index .week.NoMeals .place}} checked {{end}}>
I have a URL variable set like so:
sitename?nolunch=1
So the logic I want is that if the stored data for that day is set, the checkbox will reflect the stored value. If it hasn't been set, the box should be checked if the nolunch URL parameter is set and not checked if it's not.
How do I test for url parameters in Go template code?

Related

How to deal with dynamic parameter name in JMeter

Login page is having dynamic password field name: every time user visits the login page field name looks like PASSWORD_673834937, and on next visit, it looks like PASSWORD_673857943.
I have created many scripts which were working as of today, but in latest build they bring in this change to the password field... before this it was always PASSWORD only. So all my scripts were failing. What is the workaround, so that all my scripts start working with dynamic field name?
OLD JMETER SCRIPT using name as "PASSWORD"
NEW changes to the password field
Under register.asp sampler, add RegEx Post-Processor
Specify the following parameters:
(i.e. the regular expression is <input TYPE="password" NAME="([^"]+)")
In HTTP Request, in the row where password is provided, specify variable created by RegEx Post-Processor in Field name, instead of static name. For example, since the variable I created above is called PasswordFieldName, the HTTP Sampler should look like this (omitting irrelevant parameters):
This is a matter of missing correlation, you would need this sooner or later given you continue playing with JMeter.
The idea of bypassing dynamic parameters is building your Test Plan as follows:
Request 1 (open login page)
Extract dynamic parameters and store them into JMeter Variables
Request 2 (perform login) providing credentials and all dynamic variables from the previous step
Add CSS/JQuery Extractor (be aware that it is not recommended to use regular expressions to work with HTML data) as a child of the register.asp page and configure it as follows:
Reference Name: anything meaningful, i.e. name
CSS/JQuery Expression: input[title=Password]
Attribute: name
Replace PASSWORD_673834937 with ${name} in the new script.

Laravel: variable as form value

First Laravel Project.
I want to make an "edit screen" where the "old values" are the predefined default value of the form input field.
I tried this:{{ Form::text('brand', '$product[0]->brand') }}
But I got back
$product[0]->brand
Instead of
Test brand
What I did wrong? What's the good syntax?
Usually, Laravel should reuse the last entry the user used if the form isn't validated as you can read here :
Also, please note that the value will first come from Flash Session Input, only secondly will the value argument be used. This means if your previous request was this form it will automatically display the value the user last entered.
But, if you want, can't you use something like
{{ Form::text('brand', $product[0]->brand) }}
Because you were saying you wanted that specific string by putting ' around your variable.
please use it:
{{Form::text('brand',null,array('class'=>'form-control'))}

Spring JSP variable not assigned

I have in my JSP page code like this:
<spring:url value="" var="url"/>
EN
And issue is that parameter url in link is always set to empty String.I would expect that if I type url like localhost:8080/test the url variable will hold this value and it will be replaced in link so it would look like /change_locale?locale=EN&current=test. However it is always generated like /change_locale?locale=EN&current=.What I am doing wrong? Best regards
In
<spring:url value="" var="url"/>
Your value value is the empty String. Because of this, the URL is relative.
Spring uses UrlTag to construct the value from a <url> tag. You'll want to take a look at its createUrl method in the source code if you're curious.
In this case, it will generate a value that is the empty String and store it in a page scope attribute named url. That's what you get when rendering
${url}

How can I log the value of a variable sent in an HTTP Request sent from JMeter, if the value was first read in from a csv file

I would like to read the exact value of a variable I use to pass through an HTTP Request. I first read in many values of variables using the CSV Data Set Config. For the username, it is in the form of an email address. So, I have a variable called "email" in the Data Set Config. In the actual HTTP Request, for "name", I call it "username". For the "Value" field for this same "username", I added a time() function to it like this so I would end up creating unique users in my tests:
${email}${__time()
When I view the "Request" in a View Results Tree, I can see my parameter is listed correctly:
username=email1%40email.com1390854377360
I do not care if this is correct in real world terms. I already know that is not a valid email. That is ok for now.
What I want to know is how can I log that email that I just created on the fly? I would like to not have to pull in the whole request every time also and then use some type of Regular Expression extractor. It just seems like there should be an easy way to do this.
I think there are 2 ways,
Beanshell Pre/Post processors : you can write custom code in which you can log all your variables in some custom log file
Simple data writer : you can configure it and check save url,save field names,save response data field checkboxes that will give you complete data but in that later postprocessing on result file is required to get all usernames (email in your case).
first approach is easier and allows you create your own logging format(easy to retrieve and use somewhere else).
second approach is somewhat tedious and requires post processing.

How do you pass unchecked checkbox value using Coldfusion.ajax.submitform?

I'm stumped. I have a <cfform> and I'm saving the form info to a database using a cfc and Coldfusion.Ajax.submitform. My form uses checkboxes. What I can't seem to figure out is how to capture if a checkbox is unchecked. I've read that if a checkbox is unchecked, it doesn't get sent with the form info. I've also read that you can use <cfparam> to give the checkbox a default value so that if the checkbox is unchecked, it will still have a value e.g. <cfparam name="form.checkbox1" default="0">. Unfortunately, it doesn't seem to work when I use ColdFusion.Ajax.submitForm. Any insight would be greatly appreciated. Thanks.
Creating a proper answer so you can close this question.
Per the ColdFusion documentation: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7faf.html
Cfparam tests for the existence of a parameter (that is, a variable),
validates its data, and, if a default value is not assigned,
optionally provides one.
Mostly it's just used to create a default value for a variable of pretty much any scope.
As you have discovered, the cfparam tag must be used when the variable is required, in the processing page. cfquery param creates the variable in memory on the coldfusion server and is only available for the duration of the request (unless you use it to set a value to a persistent scope like session or application). It does not create form elements or javascript variables

Resources