rvdb86 Posted March 4, 2009 Share Posted March 4, 2009 Hi, I hope someone can help me out! I have created a script that allows my users to dynamically create a form giving each field their own atributes. The form by default has the action sendform.php and method=post. the problem is i do not know how many fields the user has created and their names is there any way in php that i can get ALL posted variables into an array or something? I would really appreciate any suggestions! Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 4, 2009 Share Posted March 4, 2009 You should probably be using an array, every form field they add, add it to the array. Then you can just count how many items are in your array and use the information in any way you need it. Quote Link to comment Share on other sites More sharing options...
rvdb86 Posted March 4, 2009 Author Share Posted March 4, 2009 wow aebstract thanks for the quick reply! My knowldege of arrays is really weak and i have never 100% understood them do you know of a good tutorial that could fill me in or do you have a small example i could look at? Sorry for my lack of knowledge but through trial and error i hope to learn Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 4, 2009 Share Posted March 4, 2009 Once you start to get them down, they can be fairly easy and very very useful. First look here: http://us3.php.net/manual/en/function.array.php, read through till you get to user comments, that will help you out in understanding how they are setup and their form. I'm not sure I have any quick easy examples, but if you read over that page and take a stab at it, you can come ask on anything you get stuck at and we can work through it. Quote Link to comment Share on other sites More sharing options...
rvdb86 Posted March 4, 2009 Author Share Posted March 4, 2009 great ill check it out right now! thanks Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 4, 2009 Share Posted March 4, 2009 Hi By default all the fields are in an array (well, several, $_REQUEST, or $_POST, or $_GET). You can loop through them, eg:- foreach ($_REQUEST as $field => $value) { // Do something here } All the best Keith Quote Link to comment Share on other sites More sharing options...
rvdb86 Posted March 4, 2009 Author Share Posted March 4, 2009 hi Keith, Could you please explain in more detail? If the form method is post would i still use $_REQUEST as $field => $value or would i use: $_POST as $field => $value am i on the right track with this:? $i = 0; while($i < count($field){ echo $value; $i++ } thanks for the suggestions! Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 4, 2009 Share Posted March 4, 2009 Hi There are several arrays of variables in php when a form is submitted. $_POST is just the post method ones, $_GET is the get method ones and $_REQUEST is both combined. So you could quite happily use $_POST as $field => $value. foreach ($_REQUEST as $field => $value) is looping through all the variables in the $_REQUEST array (ie all the POST and GET items), with each turn through the loop dealing with one field with the field name in $field and the value in $value. You cannot use your count example. You would need something like :- $i=0; foreach ($_POST as $field => $value) { echo "$field $value <br />"; $i++ } echo $i; This would give you a list of the field names and their values, and then the count of them at the end of it. All the best Keith Quote Link to comment Share on other sites More sharing options...
rvdb86 Posted March 4, 2009 Author Share Posted March 4, 2009 aebstract and Keith thank you so much for your quick replies and wonderful help. Keith your last post gave me exactly the solution i needed thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.