spryce Posted April 6, 2011 Share Posted April 6, 2011 I want to post some form identifyer when I hit submit, so that I can use this in an SQL query. Previously I used the below code and would retrieve either page1.php or page2.php etc from $_POST['subject']); <td> <select name="subject" id="subject" onchange="gotourl(this.value)"> <option value="" >Please Select</option> <option value="page1.php" >page1</option> <option value="page2.php">page2</option> <option value="page3.php">page3</option> </select> </td> will this work? <form id="form1" name="form1" value="tableName" method="post" action=""> $_POST['form1']) returns tableName...... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/ Share on other sites More sharing options...
spryce Posted April 6, 2011 Author Share Posted April 6, 2011 forget that..... thats stupid. Then I would need to reference each form by name. I need a generic reference that I can use on multiple forms. I am a newb btw. Any healp appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1197610 Share on other sites More sharing options...
monkeytooth Posted April 6, 2011 Share Posted April 6, 2011 I usually handle all my inputs on a one to one basis, as most of my inputs I require different things from.. in the form tag you don't need a value (actually I'm not even sure thats valid by W3C standards, I know Ive never seen it though). Anyway.. if your looking just to have an array of data from any given form that you want to work with that array instead of a one to one, then all you need to do is go based on $_POST without the ['whatever'] as $_POST is an array by itself if you post your form and on the page its going to if you put echo "<pre>"; print_r($_POST); echo "</pre>"; you will see all the data in said array. All though I see you mention multiple forms? Do you mean on the same page? If so then a post is a post is a post. what ever lies between <form> and </form> is fair game to $_POST on a per form tag basis once the submit button is hit within those form tags.. Anything outside of that particluar form is not submitted. Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1197657 Share on other sites More sharing options...
spiderwell Posted April 6, 2011 Share Posted April 6, 2011 what about a hidden field specifying the table associated with the form? Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1197660 Share on other sites More sharing options...
monkeytooth Posted April 6, 2011 Share Posted April 6, 2011 hidden fields work, as long as they are within the <form> tags you are submitting. Although I wouldn't hard code my table names or anything that would make any connection to actual structure of my database into a place that's visible to those who know where to look in hopes of such information. Don't want to give any would be bad users anything pertinent to work with ya know. Your concept however is alright, I would just use a different association.. say instead of TableName use some other identifier whatever you want to call it really. that you can put in your form handling script if($myHiddenValue == "thisSpecialValue"){$tableToUse = "TableName";} little extra work and processing per say. But in the end run Im a paranoid person. I don't trust anyone that comes to sites I work on cause ya never know when your gunna get that one that will just really $*(#$*RT& up your day.. Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1197668 Share on other sites More sharing options...
spiderwell Posted April 6, 2011 Share Posted April 6, 2011 yeh of course dont put the real name into the field, but I am the worst person for taking my own advice! lol Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1197680 Share on other sites More sharing options...
spryce Posted April 7, 2011 Author Share Posted April 7, 2011 That sounds exactly like what I need....... But how can I create a hidden field? What code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1198111 Share on other sites More sharing options...
Novocaine88 Posted April 7, 2011 Share Posted April 7, 2011 <input type="hidden" value="" /> And of course you can enter something into the value so you can get it later with php Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1198117 Share on other sites More sharing options...
spryce Posted April 7, 2011 Author Share Posted April 7, 2011 awesome - thanks! Quote Link to comment https://forums.phpfreaks.com/topic/232843-can-i-use-a-value-in-a-form-tag-to-select-a-db-table-from-_post/#findComment-1198147 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.