get form values other than by name in codeigniter - codeigniter

hi i am using codeigniter . i have a form , there i add hidden fields dynamically . so every hidden field is <input type='hidden' name='hidden' value="+$(this).attr('title')+"> so the name is equal .
the problem is when i submit the form and try to get my hiden field values i can only get one hidden field value , because the names are same
i print my form values
print_r($this->input->post());
i have 2 hidden fields but i get only one
Array
(
[hidden] => march
[textbox] => march
[mysubmit] => Submit
)
i can change the name dynamically of hidden field when creating , but then i don't know exactly the name of my hidden field ,
how can i get hidden field values with same name ?? is there any way to get form values other than by name ?? i tried and can not find an answer , please help .............

You'll need to use brackets in your name attributes:
<input type='hidden' name='hidden[]'>
<!-- ^^^^ -->
This will allow PHP to accept multiple inputs with the same name as an array of values, so in this case, $_POST['hidden'] will return an array of strings.
By default they are indexed starting at 0, so $_POST['hidden'][0] will get you the first one, $_POST['hidden'][1] will get you the second, etc., however - you can explicitly index them if it's easier for you, either with numbers or strings.
<input type='hidden' name='hidden[first]'>
<input type='hidden' name='hidden[second]'>
Or:
<input type='hidden' name='hidden[0]'>
<input type='hidden' name='hidden[1]'>
You can nest these as deep as you want like hidden[first][1][], and they will be treated similarly to a PHP array when you get the $_POST values, but you need the brackets in the HTML.
Without brackets, only the last field's value will be available in the $_POST array. This is a PHP feature, Codeigniter can't do anything about it.

Related

ASP Classic : Put a "variable" in a "Request.Form()"

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.

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()

Ruby Mechanize, save html as file after filling a form

I want to save the html after filling a form. lets say:
page.form.field.value = 'testing'
page.save 'test.html'
the generated test.html file don't have the modified value attribute
<input name='something' value=''>
I'm expecting:
<input name='something' value='testing'>
You want to use dom functions for that:
page.at('[name=something]')['value'] = 'testing'
In other words there's no reason to expect that changes to the Form fields will update the dom.

Scrapy Xpath query to select input tag elements

I'm using Scrapy crawl spider and trying to parse output pages to select all input tag parameter as the following :
input type: must be (text or password or file)
input id: if it's not found , select [input name] instead.
I wrote a sample code for test in Scrapy shell, but it doesn't give me the exact result.
Tested site: http://testaspnet.vulnweb.com/Signup.aspx
>>> hxs.select('//input[#id] | //input[#type="text"] | /text()').extract()
[u'<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTY0MzI4NjU4Mw9kFgICAQ9kFgICAQ9kFgQCAQ8WBB4EaHJlZgUKbG9naW4uYXNweB4JaW5uZXJodG1sBQVsb2dpbmQCAw8WBB8AZB4HVmlzaWJsZWhkZHEZ3VN6SP/C2xESDN/Y3p8zhfSB">',
u'<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWWgKJ+8rsBQLStq24BwK3jsrkBALF97vxAQKozoCcCQKpzpj7DgKSnr/eCQKSnr/eCQKSntPyAgKSntPyAgKSnseJCgKSnseJCgKSnvusAwKSnvusAwKSnu/DDAKSnu/DDAKSnoPmBQKSnoPmBQKSnre9DQKSnre9DQKSnqvQBgKSnqvQBgKSnp+5AwKSnp+5AwKSnrPcDAKSnrPcDAL3pJ3FDwL3pJ3FDwL3pLGYBwL3pLGYBwL3pKU/AvekpT8C96TZ0wkC96TZ0wkC96TN9gIC96TN9gIC96ThjQoC96ThjQoC96SVoAMC96SVoAMC96SJxwwC96SJxwwC96T9rAkC96T9rAkC96SRwwIC96SRwwICyMvj6AUCyMvj6AUCyMuXjw0CyMuXjw0CyMuLogYCyMuLogYCyMu/+Q8CyMu/+Q8CyMvTnQcCyMvTnQcCyMvHMALIy8cwAsjL+9cJAsjL+9cJAsjL7+oCAsjL7+oCAsjLw9MPAsjLw9MPAsjL9/YIAsjL9/YIAq3SwZ8KAq3SwZ8KAq3S9bIDAq3S9bIDAq3S6ckMAq3S6ckMAq3SnewFAq3SnewFAq3SsYMNAq3SsYMNAq3SpaYGAq3SpaYGAq3S2foPAq3S2foPAq3SzZEHAq3SzZEHAq3SofkFAq3SofkFAq3S1Z0NAq3S1Z0NAob5pwUChvmnBQKG+dvZCQKG+dvZCaCOP7DYDQ3mNEhISrmdoTKH9Tws">',
u'<input name="tbUsername" type="text" id="tbUsername" class="Login">',
u'<input name="tbPassword" type="password" id="tbPassword" class="Login">',
u'<input type="submit" name="btnSignup" value="Sign me up" id="btnSignup">']
All input elements of type text, password or file:
//input[#type='text' or #type='password' or #type='file']
I am not sure of what condition you want on the id or name - this will get all input elements of those three types that have either an id or name:
//input[(#type='text' or #type='password' or #type='file') and (#id or #name)]
If you want to test for the id or name (if the id does not exists) equal to something (XXXX):
//input[(#type='text' or #type='password' or #type='file') and (#id='XXXX' or (not(#id) and #name='XXXX'))]
If you want to extract the id:
//input[#type='text' or #type='password' or #type='file']/#id
I don't think extracing either the id or the name if the id is not specified is possible with standard XPaths.
I don't know Scrapy, but from a purely XPath point of view, the following should satisfy the requirements you describe:
//input[(#id or #name) and (#type = 'text' or #type = 'password' or #type = 'file')]
Also, I notice you're trying to retrieve the text content of the selected nodes. This will presumably return nothing because inputs are self-closing tags and do not hold inner content.

Validating input type number in html5

I want to restrict entry of input onto a field of type number such that input cannot be outside range of min-max specified in the html.
input type = "number" min = "1" max = "5"
Is there a way of outputting the number field without the text box and i would rather not use
"input type = range"
as slider does not show value currently selected
Please help.
Thanks.
Based on what you said, I suggest using a simple input text field and check it's value validity on submission via JavaScript (as #Kush mentions above). You could also check it as the user types, or moves focus away from that field.
<form>
Only 1 to 100 <input type="text" name="number" pattern="\d{1,2}(?!\d)|100" title="one to hundreed only">
<input type="submit">
</form>

Resources