Getting the value of dynamically created text box in PHP - php

I have a link. Whenever it is clicked, a new page will be displayed which contains data such as id, name, price and a select option with a check box. This page also contains a button. All these details (id, name, price) are fetched from a table. If the check box is checked and the button is clicked, a new page with the selected values along with a text box for each id should be displayed. If a value is entered in those text boxes and the button is clicked, I should fetch the value of the text box. I have given the text box the name id (which is retrieved from the table).

I assume the new text box is created using javascript. Give it a fixed name attribute that your PHP script knows and read it from _POST[]

Well, there are two ways of doing this.
Name your text boxes as an array. So the name would be name[] or name[2]. Then, in PHP just loop over $_POST['name'] which will be an array (or empty if no text boxes were added). That way, you only need to submit the data that exists...
The other way would be to use Javascript to do the submission. You'd need to assemble the response into a common format (JSON perhaps) and then send that to the server...
But it's definitely possible...

You can use a naming convention for the name property of the textboxes that append an integer value to the end of the whatever generic name you use. Store the number of textboxes created and once the page is posted, you can reconstruct the name of the textboxes with a loop and read the posted values.

Related

Fetching value from codeigniter form field among input fields of same name

I don't need any code, I just need the right way to do it.
What I am doing?
Here is the thing. I am making a software for a pharmacy (Drug Store). I have created a tab for shortlist for the drug. See the picture.
enter image description here
What problem I am facing?
In the last column, I have a form field to input drug or add stock. But you can see there are many form fields for so many rows. When I click to "Confirm" button, it's not gonna work cause the table has been generated using loop. So, for all the fields there are same name.
How can I take the value of input field right above the submit button. I mean when I click confirm button it will take same row's input field not others.
How can I do it? No code needed. I am using php codeigniter framework.
Thanks
create one variable like '$i' and increase it and append it on last of input name.as well as give id to submit button and append id with $i.
for eg. name_1,name_2,submit_2,submit_2
when you submit just get the id of submit button. Then get the number from id eg.2,3.take input from the same input variable id. You can do it using ajax. So it will be done without refresh page.

how to assign multiple values to an attribute through text field in Magento?

I want to create an attribute in Magento CE, in such a way that I can assign multiple values to it through text field. I know multiple values can also be assigned using multiple select or drop-down input type. But values that can be assigned to our attribute run into thousands so multiple select is not practical. Is there any way through which I can assign values through a text field which are then stored in a list or array which can be manipulated individually.?
Without gaining more information about the specifics of what you want to do, here's a few options:
Just comma-delimit your entries in the text box. The exact value will be stored for the attribute in the DB. Code that uses this attribute at some point can do an $var = explode(',' $this->getAttributeName()) call on it to get a non-associative array of the values
If you want to allow the selection of numerous possible values and place those into a serialized string for storage, use something like http://xoxco.com/projects/code/tagsinput/ but make the text-box hidden and supply the option tags in the form - edit the jQuery from that library to insert the tag name into the hidden text box on-click and change the color of the tag on the frontend so the user knows its been selected. At the form submit, your POST data just contains a comma-delimited string of those tag names. The same jQuery library can be slightly altered to render the chosen tags as being selected by parsing out the pre-stored attribute text using an explode().

Adding elements to a table from an input area

I am trying to have something like the image below in my PHP page.
(The links are in the comments. I was unable to post them here properly)
Once I enter the keyword and hit the "plus" it should appear in the table, along with the color to the right. The sequence of colors will be predetermined. If I enter a keyword again and hit the "plus" again, the keyword should appear just below the earlier keyword int the table. For the time being I am assuming the table consists of 5 rows and there are less than or equal to 5 keywords.
Also I want to have a submit button at the bottom that when clicked should send all the keywords now present to a PHP file. I have a form with the action attribute set to a PHP file. The table and the keyword input field are to be a part of a form.
I prefer using javascript and not PHP for many complications. Is there a way I can store all the keywords and then send it to the PHP file once the form is submitted?
Any help would be greatly appreciated.
You could:
Build the html form with five text inputs, all stacked on top of one
another (I think using position: absolute).
Place html table underneath inputs.
Place submit button underneath table.
Use javascript to:
hide the four text inputs that aren't currently being used
display the text input and corresponding color in the table when the user presses the +.
hide the current text input and show the next input when the user presses the +.
When user hits submit button, all five input values will be submitted to action='*.php'

Updating value of one field on change of value of other field

I am using a Joomla form add-on.
the form already captures logged-in user-name on submit.
Now I want to create two fields
verified- a button field, which allows me to add javascript code for the button.
Verified by - (it can be a calc field type, where I can use both Javascript and PHP)
Every time the button verified is clicked, the verified by field captures the logged in user's name, if the button is clicked second time by another user, it adds the name of that second user in the verified by field, not overwrite it.
Your question isn't very clear, but from the sound of the question's title you might want to check out MySQL triggers.

Passing information from forms and your own information

How do I pass information from my form plus some additional data when submitted the form. For
example if I am using PHP
I have a form and I set the method to GET; now all the fields in the form will be sent in the URL, now suppose if I want to keep a track of how many times the submit is clicked, for that if I pass the variable count along with all the data through URL, how do I do that?
How do I append this data to the existing form's data?
OR suppose if I have a field in my form where I allow to user to enter name of their employs; initially it will show 4 fields for the data, but if I click the submit type button that says MORE, then it will display 4 more fields, and similarly if again he presses more it shows 12,
so I was thinking maybe I could sent a variable $count along with the form data through URL, but I don't know how to do it.
I would user a hidden field with the "count" value. It will then be passed with all the other form input variables but won't actually be visible to the user on in the form:
<input name="field_name" type="hidden" value="cout_value_that_changes" />
You can change - Field_name - to what ever you want it to be and the value should be incremented every time the submit button is pressed - incremented with PHP -
something like:
$count++;
value="<?php echo $count;?>"
Best solution for your requirement seems Use of JQuery.
Add your fields dynamically using JQuery.
For ref. you may check : http://docs.jquery.com/Main_Page
Without using JQuery, you can have Hidden field which would contain count of the field.
we have to pass count in GET request and while showing field in php, check count field.

Categories