rossdeane Posted July 7, 2008 Share Posted July 7, 2008 Hi People, Wonder if you can help me out.. I'm currently doing a few forms in php, and they can be quite large. The problem I have is that its very time consuming and boring to extract all the form fields into variables, for example $someformfield= $_POST['someformfield']; I've been doing a separate line for each field and just putting it in a separate include file for neatness, but surely theres a quicker way than doing this 50+ times? ??? I considered just naming the fields with numbers and then extracting each one inside a loop, but its not ideal because it would make the form code confusing... Any help appreciated, thanks Ross Link to comment https://forums.phpfreaks.com/topic/113581-easier-way-to-extract-form-variables/ Share on other sites More sharing options...
gigas10 Posted July 7, 2008 Share Posted July 7, 2008 Use an array? Link to comment https://forums.phpfreaks.com/topic/113581-easier-way-to-extract-form-variables/#findComment-583583 Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 What does this have to do with OOP? Link to comment https://forums.phpfreaks.com/topic/113581-easier-way-to-extract-form-variables/#findComment-583586 Share on other sites More sharing options...
PFMaBiSmAd Posted July 7, 2008 Share Posted July 7, 2008 $_POST is already an array variable. $_POST['someformfield'] is a perferctly fine variable name. Assinging $someformfield = $_POST['someformfield'] is a waste of processor time and just doubles the amount of variable storage space needed. If you really want to do this, use the extract() function with the EXTR_PREFIX_ALL parameter and a $prefix string, something like - extract($_POST, EXTR_PREFIX_ALL, "form_"); Link to comment https://forums.phpfreaks.com/topic/113581-easier-way-to-extract-form-variables/#findComment-583599 Share on other sites More sharing options...
numan82 Posted July 21, 2008 Share Posted July 21, 2008 hi, the simple solution is using for each loop on $_Request(it is a request array that contains the form data being to be submitted) for example foreach($_Request as $key=>$value) { $InsertArray = $Value; } and than using this $InsertArray, you can insert a records into the specifice table of your DB. Hope it it will give you some idea. Thanks! Link to comment https://forums.phpfreaks.com/topic/113581-easier-way-to-extract-form-variables/#findComment-595294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.