peddel Posted August 21, 2008 Share Posted August 21, 2008 Im looking for the following : When a person hits the submit button of a form, the form gets all the entered values from the textfields and puts them in session variables. Now because a form in advance of that one defines how many textfields there will be, depending on the input on the previous form, i cant just use functions like $_POST['textfieldname'] becuz i dont know in front which fields will be displayed. Anyone can give me a clue how to solve this problem? Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 none got a clue? Quote Link to comment Share on other sites More sharing options...
ninedoors Posted August 21, 2008 Share Posted August 21, 2008 What form fields are available? Are they all related or are they different field names completely? If you don't know what filed names are being passed what are you going to do with the information? Can you explain exactly what you are trying to do. Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 well lets asume the following FORM 1 ------- Person inserts name of a pressure valve and the value with it TEXTFIELD1 : Please enter the valve name : <input type='text' name='valvename' /> TEXTFIELD2 : Please enter the value : <input type='text' name='value' /> Then the person gets redirected to a page where a checkup happens when he submitted the 1ste form FORM2 ------- Value has to be between upper and lower value. With MySQL i retrieve these values from a database and compare em with $_POST['value'] Till here it still works. NOW when the value is not between the border values i do the following : Please enter a new value for the valve = <input type='text' name='valueNew' /> Immagine the above situation counts for like 10 fields. This means that on form2 there will be sometimes 0 requests for new value, or there will be 10 values asked. I submit the new form with the new values and go to FORM3 FORM3 ------ Now has to know what values where changed so he can put them away in a session variable. BUT how can he know what fields where on form2 and which were not SO i cant use the $_POST['valueNew'] CUZ i dont know if that field was shown our not HOPE this helps Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 21, 2008 Share Posted August 21, 2008 Use a foreach loop: <?php foreach ($_POST as $fld => $val) { // // do your work // }?> Ken Quote Link to comment Share on other sites More sharing options...
ninedoors Posted August 21, 2008 Share Posted August 21, 2008 I would just collect all your pressurre valve inputs in one array and the values in another from form1. TEXTFIELD1 : Please enter the valve name : <input type='text' name='valvename[]' /> TEXTFIELD2 : Please enter the value : <input type='text' name='value[]' /> Then you can use the keys from the array to know which one need to be changed. Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 Use a foreach loop: <?php foreach ($_POST as $fld => $val) { // // do your work // }?> Ken can u explain once i run trough all those $_POST variables how i can know the name of the field that he is in for that moment? becus i would do something like this foreach ($_POST as $fld => $val) { //line to get the "name of the field" $var = $_SESSION['name of the field'] }?> ALREADY big thx for the help Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 I would just collect all your pressurre valve inputs in one array and the values in another from form1. TEXTFIELD1 : Please enter the valve name : <input type='text' name='valvename[]' /> TEXTFIELD2 : Please enter the value : <input type='text' name='value[]' /> Then you can use the keys from the array to know which one need to be changed. I will try this one if i cant get kens idea working in my script Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 I used this code in the php page i go to when form is submitted. The result was just a blank page ! CODE : <?php foreach($_POST as $fld => $val){ print($fld); print($val); print("<br />"); } ?> What am i missing here? Quote Link to comment Share on other sites More sharing options...
ninedoors Posted August 21, 2008 Share Posted August 21, 2008 You could do something like this: <?php $valve_name = $_POST['valvename']; $valve_value = $_POST['value']; for($i=0; $i<count($valve_name); $i++) { //this is where you will check your DB with $valve_name[$i] and $valve_value[$i]. } ?> Maybe I am misunderstanding what yuou need to do or how your form1 is setup. Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 You could do something like this: <?php $valve_name = $_POST['valvename']; $valve_value = $_POST['value']; for($i=0; $i<count($valve_name); $i++) { //this is where you will check your DB with $valve_name[$i] and $valve_value[$i]. } ?> Maybe I am misunderstanding what yuou need to do or how your form1 is setup. I think u dont get what i mean with my setup, and i dont really know how to explain it better. I think KEN gots a clue on what im doing, i just want him to check where i go wrong now. No offense tough ninedoors! But i think ur thing isnt doing what i want Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 anyone else can help me out ? since Ken left forums ??? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 21, 2008 Share Posted August 21, 2008 At the top of your test script, put <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> This will show you what is coming from the form via the $_POST array. This assumes that you have 'method="post"' in your form tag. If you have method="get" or no method change all references of $_POST to $_GET Ken Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 k i tried this, now it seems my $_POST is an empty array how that can be, i got no clue, dus i got like 5 fields, inside the form im submitting let me check the code again :-\ Quote Link to comment Share on other sites More sharing options...
peddel Posted August 21, 2008 Author Share Posted August 21, 2008 now im totally confused ??? i got the form made like this <form name='formulier1' action=''> action not filled so it checks the same page again </form> then inside the form i got a part between if(!isset($_POST['submit'])){ ... enter code here ... } and a part between if(isset($_POST['submit'])){ ... enter code here ... } In the second part i enter that code u gave me, for showing the submitted $POST array It show up as a empty array tough i see the fields visual :S Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 21, 2008 Share Posted August 21, 2008 You don't have a method in the form tag, so the method defaults to GET and submitting will populate the $_GET array not the $_POST array. Either change all the references of $_POST to $_GET in your script or add a method to the form tag: <form name="formulier1" action="" method="post"> Ken Quote Link to comment Share on other sites More sharing options...
peddel Posted August 22, 2008 Author Share Posted August 22, 2008 You don't have a method in the form tag, so the method defaults to GET and submitting will populate the $_GET array not the $_POST array. Either change all the references of $_POST to $_GET in your script or add a method to the form tag: <form name="formulier1" action="" method="post"> Ken thx man found out indeed that was the problem >_< Still its pretty dumb, making those minor stupid mistakes and searching on it for hours THX for helping my problem is solved ! 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.