Get value with $_POST from multiple brackets - post

<input type="text" class="text" id="attachments-1-vid_id" name="attachments[1][vid_id]" value="1qaq0F-SXpo8">
<input type="text" class="text" id="attachments-2-vid_id" name="attachments[2][vid_id]" value="2qaq0F-SXpo8">
<input type="text" class="text" id="attachments-3-vid_id" name="attachments[3][vid_id]" value="3qaq0F-SXpo8">
<input type="text" class="text" id="attachments-4-vid_id" name="attachments[4][vid_id]" value="4qaq0F-SXpo8">
This is my input. I want to check it with only [vid_id]. Is it possible?
If any input posted
if( isset($_POST['vid_id']) ) {
//do it...
}

You are accessing the vid_id index which isn’t really what is passed in the $_POST superglobal.
The solution is based on two assumptions.
Only that input exist.
This is pretty straight forward:
<?php
if(isset($_POST[‘attachments’][231][‘vid_id’]){}
OR
<?php
if(array_key_exists(“vid_id”, $_POST[‘attachments’][231])){}
Similar inputs also exist and you want to perform for multiple inputs.
By this, I mean..
<input type=text name=attachments[][vid_id] />
.....
<input type=text name=attachments[][vid_id] />
<input type=text name=attachments[][vid_id] />
For this, you have to insert it in a loop.
<?php
foreach($_POST[‘attachments’] as $arr){
if(array_key_exists(“vid_id”, $arr){
// do stuff
}
}

Related

Why does "<input id='id' type=text name='id' value='H123'>" not get "POST"ed by FormData

When I submit the following form
<form name="fileUpload" id="fileUpload" method="post" action="javascript:void(0);" enctype="multipart/form-data">
<input id='id' type=text name='id' value='H123'>
<div class="file_browser">
<input type="file" name="multiple_files[]" id="_multiple_files" class="hide_broswe" multiple />
</div>
<div class="file_upload">
<input type="submit" value="Upload" class="upload_button" />
</div>
</form>
The files[] get uploaded OK but input "#id" is not in the $_POST array.
I need it because I want to pass the name of the directory that the images are to be stored in.
I notice that you are missing quotation marks around 'text' in
<input id='id' type=text name='id' value='H123'>
Which should be:
<input id='id' type='text' name='id' value='H123'>
Besides that I can't see any obvious reason why it shouldn't work.

Change the width of a SINGLE JQuery Mobile Input field?

The other two answers on this question propose overriding
div.ui-input-text {}
However, I have multiple input fields on this page and also within my project. So those answers won't work as they would effect everything on my page or project.
How can I modify a single text input?
A class designation in the input tag doesn't work. If I encapsulate the input with a div tag it still doesn't work. I'm trying to put an icon at the end but it seems all Jquery mobile text input takes the entire screen.
<input class="address" type="text" name="address" id="basic"
placeholder="Street Address, City, State" />
<input type="button" value="FindMe" data-icon="eye" data-iconpos="notext">
CSS, No Effect!
.address {
width: 200px !important;
}
Now, I could still switch to Bootstrap if that's the better way to go on this project. It seems to have .col-xs-* classes that solve this problem.
Thanks in advance.
Instead of directly setting the class on the input,jQM provides a data-attribute for inputs called data-wrapper-class (api doc: http://api.jquerymobile.com/textinput/#option-wrapperClass). This allows you to apply a class directly to the outermost wrapping DIV that jQM adds when enhancing the textbox.
<input data-wrapper-class="address" type="text" name="address" id="basic"
placeholder="Street Address, City, State" />
Working DEMO
It is maybe bit late to answer this, but maybe for others looking for the same thing (I was :-)
You can put your address in a div:
<div class="myContainer">
<label id="lbAddress">Provide the address</label>
<input class="address" type="text" name="address" id="address" />
<input class="address" type="text" name="Street" id="Street" />
<input class="address" type="text" name="City" id="City" />
<input type="button" value="FindMe" data-icon="eye" data-iconpos="notext">
</div>
<div><input class="other" type="text" name="other" id="other"/></div>
Then select your container and just the input inside that container in the CSS:
.myContainer > .ui-input-text
{
width:200px;
}
demo: https://jsfiddle.net/petitbarzun/cfazq5k5/
Reading your comments on the answer from ezanker, if you want all the inputs to appear on one line, there needs to be a container with ui-field-contain like this (the label should be there too):
<div class="ui-field-contain">
<label id="lbAddress" style="display:none"></label>
<input class="address" type="text" name="address" id="address" />
<input class="address" type="text" name="Street" id="Street" />
<input class="address" type="text" name="City" id="City" />
<input type="button" value="FindMe" data-icon="eye" data-iconpos="notext">
</div>
<div><input class="other" type="text" name="other" id="other"/></div>
The CSS then looks like this:
.ui-field-contain > #lbAddress~[class*=ui-input-text]
{
width:219px;
}
demo http://jsfiddle.net/petitbarzun/cfazq5k5/1/

Jinput not working for joomla

I've been stuck on this problem with no clue as to why this doesn't work.
I'm using Joomla 2.5 and building my own component.
I have a 'Books' and 'Book' view. 'Books' lists all the books from the database and 'Book' is where I add/edit my book item. I'm trying to pass a value from 'Books' to 'Book' but it doesn't work.
I've set up an input text with a value to pass on.
<input type="text" id="test" name="test" value="testvalue" />
views/books/tmpl/default.php
<form action="<?php echo JRoute::_('index.php?option=com_test'); ?>" method="post" name="adminForm">
<table class="adminlist">
<thead><?php echo $this->loadTemplate('head');?></thead>
<tfoot><?php echo $this->loadTemplate('foot');?></tfoot>
<tbody><?php echo $this->loadTemplate('body');?></tbody>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
<!-- For sorting -->
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
<input type="text" id="test" name="test" value="testvalue" />
</div>
</form>
And in my book view.html.php file views/book/view.html.php
$jinput = JFactory::getApplication()->input;
echo 'value:'.$jinput->get('test');
There will be no value. I've tried $_POST('test') but it still doesn't work. Can anyone please point me at the right direction?
The Post data should be received in Controller not in view.
Once you submit the form it should have controller and model to handle the POST data.
check this link and understand the work flow, then on your controller you can try the same code it will works.
Joomla MVC component structure
Hope its helps..

How parse checkbox values in server side(rails)?

I am beginner in ruby + rails.
I have problem to get values in controler of checkbox with params[] of rails.
The Case:
I have simple form that that have checkbox and i want to sent reqular request to controller action with user checked values.
The problem that params[:rating] can have few values.
My case:
html user side:
<form id="ratings-form">
<input name="rating" type="checkbox" value="G">G
<input name="rating" type="checkbox" value="PG">PG
<input name="rating" type="checkbox" value="PG-13">PG-13
<input name="rating" type="checkbox" value="R">R
<input type="submit" value="refresh">
</form>
controller action code to parse checked values: (get error 1. params[:rating] == nil or params[:rating] == string)
params[:rating].each do |rat|
p rat;
end
What should i change in the code to make it work?
Thanks
Try this HTML
<input name="rating[]" type="checkbox" value="G">G
<input name="rating[]" type="checkbox" value="PG">PG
<input name="rating[]" type="checkbox" value="PG-13">PG-13
<input name="rating[]" type="checkbox" value="R">R
Then you should have an array in params[:rating].

MVC Razor String Concat

I am using Razor to generate a form. I want to create HTML elements based on some value from it's model property.
for example, if a model contains Id property, and I want to generate html tags as follows
<input type="hidden" name="1_chk" />
<input type="hidden" name="2_chk" />
<input type="hidden" name="3_chk" />
So I used the following syntax, and it failed. Can anyone help me out with this?
<input type="checkbox" name="#Id_chk" />
Thanks
I think this should work for you:
<input type="checkbox" name="#(Id)_chk" />
another option:
<input type="checkbox" name="#(Id + "_chk")" />

Resources