Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,150,562 members, 7,809,056 topics. Date: Thursday, 25 April 2024 at 09:58 PM |
Nairaland Forum / Science/Technology / Webmasters / How To Load Form Inputs Into An Array. (936 Views)
How To Optimize Wordpress Page Speed And Load Time / Why Does This Mysql Query Display "array" Instead Of The Result / Getting The First Character Of Array Values, Php ? (2) (3) (4)
How To Load Form Inputs Into An Array. by sunday478(m): 5:34pm On Jul 29, 2014 |
hi. Webmaster. I have about 15 form fields, I created it with a loop. And assigned different names. Like item1, item2, ... when entering the form, the user is free to enter any of the 15 fields, he may choose to enter just 5 or maybe the 15. When he enter maybe the five I will collect those five and and prompt them to enter other values for the value the already entered. Let's say U are asked to enter name of books you have read. You will then be asked to enter the price you bought the books. //I have succesfully achieve the above. What I want to achieve now is: How I could get the inputs for any of the form fields that is filled. I tried to use loop to load the posted values. But it is not working. Because I want to do the validation. I will like to know how to load any of filled fields into an array. Or if there is a way to go about It. Dual Core, et al. |
Re: How To Load Form Inputs Into An Array. by GodMode: 8:08pm On Jul 29, 2014 |
are you using javascript or php or both |
Re: How To Load Form Inputs Into An Array. by sunday478(m): 5:22pm On Jul 31, 2014 |
PHP |
Re: How To Load Form Inputs Into An Array. by GodMode: 7:29pm On Jul 31, 2014 |
sunday478: PHP U'll need to get the name attribute from the input. For example
If u want to get the name attribute in php use either $_GET[your name attr here] or $_POST[your name attr here]
Since u're using PHP u'll use a database, so u'll have to write it into the database. |
Re: How To Load Form Inputs Into An Array. by GodMode: 7:40pm On Jul 31, 2014 |
for example:
it grabs the input and adds it to the $name array the only problem is once you hit submit the page refreshes so it doesn't append/add it to the array. as in it changes what's in that new input. but its possible to add/append it to a database or a file or both. |
Re: How To Load Form Inputs Into An Array. by GodMode: 7:51pm On Jul 31, 2014 |
but its possible in javascript... |
Re: How To Load Form Inputs Into An Array. by jumox: 9:07pm On Jul 31, 2014 |
sunday478: hi. Webmaster.Problem i have with problem solving is actually understanding the problem. Whenever I do, the rest is just a matter of time. Now to your question, the thing is, I dont understand it. But when i intend to get values of fileds returned in a loop. I do it like this: First the field is named like this: <input type="text" name="price[]" /> * hope you see the [], thats where the trick is. With the [] above in the 'name' attribute of the field, you are already putting it in array. *** Now, $_POST['price'] is an array which you can then manipulate like any other array value. Am I missing something? |
Re: How To Load Form Inputs Into An Array. by cbrass(m): 4:18pm On Aug 01, 2014 |
U will have to use a database to achieve this |
Re: How To Load Form Inputs Into An Array. by Cybergenius(m): 12:28am On Aug 02, 2014 |
What tou requested for, coded with Javascript, NOTE: seperate book names with commas! <input type="text" value="english book, math book" id="books"> <button onClick="askprice()">Enter price!</button> <script> function askprice(){ var inp = document.getElementById("books".value; var splitin = inp.split("," var pricearray = new Array(splitin.length); //prompt for the price for(i=0;i<splitin.length;i++){ pricearray[i] = prompt("How much for " +splitin[i],"₦" } for(p=0;p<pricearray.length;p++){ alert(splitin[p] +" costs "+pricearray[p] +"₦" } } </script> |
Re: How To Load Form Inputs Into An Array. by sunday478(m): 11:22pm On Aug 06, 2014 |
Thanks Guys, have solved the problem |
Re: How To Load Form Inputs Into An Array. by jumox: 2:02am On Aug 07, 2014 |
sunday478: Thanks Guys, have solved the problemtell us how.. |
Re: How To Load Form Inputs Into An Array. by sunday478(m): 5:27am On Aug 07, 2014 |
jumox: tell us how..The field I wanted to post from was enabled. I previously disabled it, but I wanted to get the value it was carrying. I guess the fault was on my part stating the actuall problem. |
Re: How To Load Form Inputs Into An Array. by sunday478(m): 5:28am On Aug 07, 2014 |
jumox: tell us how..God help me to be able to explain this. I tried to explain if it makes any sense. What i did was that, I created 15 text fields with a for loop. The form was recursive So i said If the submit button is not set it should create the form{15 txt field} After submiting the the form, it must have been set now, so I tried to collect the only the field that was filled. Mind you, I have also used the name the fields with the help of the loop. i.e app1, app2, ... App15 \\ so i said if the field is not empty, it should Do a for loop and get was was posted in any of the 15 fields, so in that case if the user decide to fill 10 fields I will just collect those 10 and and give him or her another form to filled based on the 10 fields which were filled. there fore I will collect the value into another text field, to enable me post it to another page so that I can do calculation based on both the app and the number enter for the app. That was when my problem came. I disabled the field that already has value, because I dont want the user to edit what he or she has already enter again. e.g the app field is disabled but you will have to enter a number value for the app. App1(field) number(field) App2(field) number(field) etc |
Re: How To Load Form Inputs Into An Array. by dhtmlx2: 7:59am On Aug 07, 2014 |
You have succeeded in confusing us rather than convincing us. . . |
Re: How To Load Form Inputs Into An Array. by sunday478(m): 4:06am On Aug 09, 2014 |
dhtmlx2: You have succeeded in confusing us rather than convincing us. . .Yes, I admit to that. Maybe I will just have to paste the code them comment on it. |
Re: How To Load Form Inputs Into An Array. by shadowwalker201: 2:19am On Aug 10, 2014 |
[img]http://www.?aff=391[/img] okay |
(1) (Reply)
Facebook Page With 214k Active Nigerian Fans For Sale At Cheap Rate / Problem Validating Contact Form In Frontpage! / Need Your Advice Nairalanders
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26 |