Codigniter replace dots in my input names with underscores - codeigniter

When I submit a form, Codigniter replace input names containing dots (.) with underscores (_). Here is a simple example:
<form method="post">
<input type="text" name="client.firstname" />
<input type="text" name="client.lastname" />
<input type="submit" />
</form>
$_POST contains now:
Array
(
[client_firstname] => xxxxx
[client_lastname] => yyyyy
)
So client.firstname became client_firstname with no reason?!
Do you have any idea of what is happening?

That is not CI doing this, but PHP itself – and it is a remnant of the “olden days” before there were $_POST/$_GET/etc., when external parameters where imported into the global variable scope directly; because variable names can not contain a . in PHP, because that is also the concatenation operator.
And this is documented as well, http://php.net/manual/en/language.variables.external.php:
Note:
Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"].

Related

How To Line Break Inside Code Tag In .slim

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

Jmeter regular expression extractor in hidden value

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.

How can I wrap a div around existing elements?

I'm trying to parse an existing document and modify it by wrapping a div around some existing form elements.
HTML form looks a bit like this:
<form>
<label for="username">Username:</label>
<input name="username" type="text" />
<label for="password">Password:</label>
<input name="password" type="password" />
</form>
I can parse the document OK with Nokogiri and i'm aware of the wrap method but i'm struggling to grasp how to select both the label and input tags in one go and then wrap a div around these. So the result I am looking for is:
<form>
<div class="form-group">
<label for="username">Username:</label>
<input name="username" type="text" />
</div>
<div class="form-group">
<label for="password">Password:</label>
<input name="password" type="password" />
</div>
</form>
I have tried various XPaths / CSS selectors and can create a nodeset of just labels/inputs or all of the elements of the whole form. Is there any way to achieve this modification?
A single XPath expression can only return a single collection of nodes, so in order to achieve what you want you will need to make several queries, one for each label – input pair.
You can select an individual pair with something like this, assuming the markup is well behaved (i.e each input has a label before it):
//label[1] | //label[1]/following-sibling::input[1]
This will select the first label and the following input. However you want to select all such pairs. One way would be to first select all the label nodes, and then for each label select it and the following input.
labels = doc.xpath("//form/label")
labels.each do |l|
nodes = l.xpath(". | ./following-sibling::input[1]")
# nodes now contains a label-input pair...
end
I don’t think the wrap method will work to add a div element as an ancestor to each pair, as it will add the element to each member of the nodeset. You will probably have to move them manually, something like
labels = doc.xpath("//form/label")
labels.each do |l|
# Select this node and its neighbour.
nodes = l.xpath(". | ./following-sibling::input[1]")
# Create the new element, and add it before the label.
div = Nokogiri::XML::Node.new('div', l.document)
l.before(div)
# Move each of the pair onto this new element.
nodes.each do |n|
div.add_child(n)
end
end
Note that this method doesn’t move any text nodes, so you may find the whitespace of your document changes a bit.

filter_input behavior for integer input tag name

I have form inputs that have their name attribute in Integer like below
<input type="hidden" name="100351312" value="test" />
If I use
echo filter_input( INPUT_POST, '100351312' )
It returns NULL
Whereas
echo $_POST['100351312'] prints the value correctly.
filter_input really needs three inputs; the type, the variable (both of which you have) and the filter, which you don't have. Here are some types of filters: http://php.net/manual/en/filter.filters.php
That said, if you're using WordPress you can almost always find a WordPress helper function you can use instead of filter_input()

Regular Expression - How to validate price field if I enter below 30?

I have used pattern I want to price equal 30 or Greater BUT not less.
Look my html code -
<input type="text" required="required" pattern="29+\.[0-9]*[1-9][0-9]*$" data-error="#Please enter price equal 30 or more" placeholder="Price" id="price" class="form-control" autocomplete="off" name="price" />
<div class="help-block with-errors"></div>
Above co I have used pattern="29+\.[0-9]*[1-9][0-9]*$" but this pattern not working. I have tried in different expression like 29*\.[0-9]*[1-9][0-9]*$, ^\d{30,}$, ^[0-9]\{30,}\$ these expressions also not working.
I am using bootstrap validator. Link = http://1000hz.github.io/bootstrap-validator/#validator-examples
Please help me.
*Edit : *
Now I am using ^[3-9]+\d*$ this is working fine. But it takes 3 or more than 3. I need 30 or more
You really should not be using regexes for this kind of task. But if you do want to, try this:
([3-9][0-9]|[0-9]{3,})

Resources