The scenario is I would like to write a hidden field with a guid value generated by the server.
Why does
<input type="hidden" id="sampleGuid" value="#{Guid.NewGuid().ToString()};" />
yield 'value=""' while
#{
string token = Guid.NewGuid().ToString();
<input type="hidden" id="sampleGuid" value="#token" />
}
properly fill in 'value' with a guid?
You need parentheses instead of braces.
#{ ... } will execute ordinary statements, but won't print anything.
#(...) will print the value of an expression. (and will HTML-encode it)
You've wrapped Guid.NewGuid().ToString() in curly braces.
That just means you want to execute the code, not ouput it.
If you're trying to output a value, wrap the code in parenthesis.
Related
So I've been looking all up and down Google and I've got nothing. So can someone help?
I have my .slim file all set up and I'm trying to and a pre - code section with a line break in it...
pre
code[class="language-markup" id="copyHTML-1"]
= '<label for="name-1">Label</label>\
<input id="name-1" type="text" name="name" required>'
The output is...
<label for="name-1">Label</label>\
<input id="name-1" type="text" name="name" required>
I get the line break but I get the trailing backslash. How do I get a link break in there with no trailing backslash?
Thanks in advance.
Actually, line break in string is "\n" in Ruby, and \n must be placed in double quotes "", so you could try this:
= "<label for='name-1'>Label</label>\n
<input id='name-1' type='text' name='name' required>"
Update part:
Or you could just use slim syntax:
label[for="name-1"]
| Label
input#name-1[type="text" name="name" required]
Sounds like you might want to enable the Slim pretty-print feature, which indents nested tags on different lines.
For Rails, you could set this in an environment file., for example config/environments/development.rb:
# Indent html for pretty debugging and do not sort attributes
Slim::Engine.set_options pretty: true, sort_attrs: false
The Slim documentation has more info:
https://github.com/slim-template/slim#configuring-slim
I have a form that will send an array of data to an ASP page.
Let's say this array is called "matrix".
Usually, on the ASP receiving the form, I will write this out to retrieve the form inputs from the array "matrix".
Request.Form("matrix[]")(i) where i = 1, 2, 3 which are the elements in the array.
Let's say I want to do make a variable like this
a="matrix"
and I want to use this variable a and put it into the request form, instead of writing "matrix", so that it would look something like this
Request.Form(a[])(i)
How can it be done? For now, all my attempts are showing blank. e.g. when I try to make them appear on the page with response.write, nothing shows up.
Please help me or let me know if it cannot be done, I've been spending hours on this.
Request.Form("matrix[]") is taking a string value of "matrix[]" not an array of strings called "matrix".
So you need to do either
a = "matrix[]"
Request.Form(a)(i)
or
a = "matrix"
Request.Form(a & "[]")(i)
Unlike PHP which requires adding square brackets, in classic ASP you just have to give the same name to the elements you want to be combined into an array.
The HTML should be:
<input type="text" name="matrix" />
<input type="text" name="matrix" />
<input type="text" name="matrix" />
Then you can iterate over the submitted values like this:
For x=1 To Request.Form("matrix").Count
Response.Write("Value of matrix #" & CStr(x) & "is: " & Request.Form("matrix").Item(x))
Next
Note that all elements are included, even if user left them empty.
I have a hidden code from which I am trying extract the hidden field- 320365
<fieldset class="inputs"><ol></ol></fieldset><input id="activity_id" name="activity[approval_processor][approvals_attributes][0][id]" type="hidden" value="320365" />
and I tried -
[approvals_attributes][0][id]" type="hidden" value="(.+?)"
but even the Regex Tester is not showing the number 320365. What am I doing wrong?
Almost correct, you just need to escape [ and ] as they have a special meaning in RegEx:
\[approvals_attributes\]\[0\]\[id\]" type="hidden" value="(.+?)"
Also if you know that the value is supposed to be a number, it might be better to limit it to numbers only:
\[approvals_attributes\]\[0\]\[id\]" type="hidden" value="([0-9]+)"
\[approvals_attributes\]\[0\]\[id\]" type="hidden" value="(.+?)"
or you can also use the simple eq
type="hidden" value="(.+?)"
you can also use the website - https://regex101.com/
to write any regular expressions.
Smarty-3.1.20
Rewriting php webapp backend. Using Smarty because it was required a few years back, worked and why not but now it's wrecking my head. Nested template outputting checkboxes.
Why does the in_array return true if I paste one of the values as a string but not if I reference as a variable? Arrays are var_dump-ed and are arrays and {$otherArray[0]} returns correct variable. $anArray[loop] is printing the correct variable. No extra blanks in array strings. Stop me before I throw it all out, paste json into the bottom of the html and do it all with javascript (next time definitely)
tl;dr:
in_array is not returning true from a variable but is from a string?
<input type='checkbox' name='{$anArray[loop]}' value='{$anArray[loop]}'
{if in_array($anArray[loop]}, $otherArray)} checked{/if}>
<br />
{$anArray[loop]}}
Well, it seems you don't use $ sign here correctly, it should probably be:
<input type='checkbox' name='{$anArray[$loop]}' value='{$anArray[$loop]}'
{if in_array($anArray[$loop]}, $otherArray)} checked{/if}>
<br />
{$anArray[$loop]}}
Try with:
{if $anArray.$loop|in_array:$otherArray}checked{/if}
I am trying to match the value of the following HTML snippet:
<input name="example" type="hidden" value="matchTextHere" />
with the following:
x = response.match(/<input name="example" type="hidden" value="^.+$" \/>/)[0]
why is this not working? it doesn't match 'matchTextHere'
edit:
when i use:
x = response.match(/<input name="example" type="hidden" value="(.+)" \/>/)[0]
it matches the whole html element, and not just the value 'matchTextHere'
^ matches start of a line and $ matches end of the line. Change ^.+$ to \w+ and it will work for values that doesn't contain any symbols. Make it a parenthetical group to capture the value - (\w+)
Update: to match anything between the quotes (assuming that there aren't any quotes in the value), use [^"]+. If there are escaped quotes in the value, it is a different ballgame. .+ will work in this case, but it will be slower due to backtracking. .+ first matches upto the end of the string (because . matches even a "), then looks for a " and fails. Then it comes back one position and looks for a " and fails again - and so on until it finds the " - if there was one more attribute after value, then you will get matchTextHere" nextAttr="something as the match.
x = response.match(/<input name="example" type="hidden" value="([^"]+)" \/>/)[1]
That being said, the regex will fail if there is an extra space between any of the attribute values. Parsing html with regex is not a good idea - and if you must use regex, you can allow extra spaces using \s+
/<input\s+name="example"\s+type="hidden"\s+value="([^"]+)"\s*\/>/
Because you have a start-of-line token (^) and an end-of-line token ($) in your regular expression. I think you meant to capture the value, this might solve your problem: value="(.+?)".
Beware, though, that processing html with regular expressions is not a good idea, it can even drive you crazy. Better use an html parser instead.
You don't need the ^ and $:
x = response.match(/<input name="example" type="hidden" value=".+" \/>/)[0]
you just need to change [0] to [1]
response='<input name="example" type="hidden" value="matchTextHere" />'
puts response.match(/<input name="example" type="hidden" value="(.*?)" \/>/)[1]
matchTextHere