coffejor Posted April 30, 2007 Share Posted April 30, 2007 Hello all, I have an order form that is built dynamically from my products database and would like to create a dynamic validation and form processor. I have created a good validation scheme by hardcoding the names of the fields from the orderform, an example is as follows $two_a = $_POST['PROD_cub_bear_patch_3x3_4']; $two_b = $_POST['PROD_cub_bear_patch_special_10']; $two_c = $_POST['PROD_cub_club_patch_3']; The names like PROD_cub_bear_patch_3x3_4 are stored in fields in a database corresponding to their appropriate product and can be easily retrieved. I would like to make a while loop that goes through the database and creates the variable dynamically from the post based on whats in the database. A possible solution is as follows $result = @mysql_query('SELECT * FROM products WHERE category AND status="1"'); while ($row = mysql_fetch_array($result)) { $name = $row['name']; echo '$'.$name.' = $row[/''.$name.'/'];'; } *NOTE: $name is the name of the product field that is stored in the database I'm not sure how to make this work and would be really appreciative of any input/insight that any of you may have. Thanks in advance. Jordan Link to comment https://forums.phpfreaks.com/topic/49271-solved-validation-for-a-dynamic-form/ Share on other sites More sharing options...
neel_basu Posted April 30, 2007 Share Posted April 30, 2007 Take a look at the http://zigmoyd.sourceforge.net/man/ums.php#validate Link to comment https://forums.phpfreaks.com/topic/49271-solved-validation-for-a-dynamic-form/#findComment-241469 Share on other sites More sharing options...
redbullmarky Posted April 30, 2007 Share Posted April 30, 2007 dynamic variables can be constructed using braces after the $, so: <?php $animal = 'dog'; ${$animal} = 'woofs'; echo $dog; // output: woofs ?> Link to comment https://forums.phpfreaks.com/topic/49271-solved-validation-for-a-dynamic-form/#findComment-241472 Share on other sites More sharing options...
coffejor Posted April 30, 2007 Author Share Posted April 30, 2007 That worked perfectly. Thanks, I owe you one! Link to comment https://forums.phpfreaks.com/topic/49271-solved-validation-for-a-dynamic-form/#findComment-241670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.