I have been searching, for quite some time now, for any information/tutorials on how to create a completely dynamic web form.. This form will pull the fields out of the database and display them on the page, then if the user wishes, they may edit any of the fields or add/delete fields from the form.. Anybody out there seen a tutorial on this, or at least get me pointed in the right direction.. I have created this database table which holds all the field information.. DROP TABLE IF EXISTS `dw_fields`; CREATE TABLE `dw_fields` ( `field_id` INTEGER unsigned NOT NULL auto_increment, `field_category` varchar(255) NOT NULL default '', `field_name` text NOT NULL, PRIMARY KEY (`field_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; -- -- Dumping data for table `dw_fields` -- INSERT INTO dw_fields VALUES(1, 'Customer Information', 'Bride'); INSERT INTO dw_fields VALUES(2, 'Customer Information', 'Groom'); INSERT INTO dw_fields VALUES(3, 'Customer Information', 'Address'); INSERT INTO dw_fields VALUES(4, 'Customer Information', 'City'); INSERT INTO dw_fields VALUES(5, 'Customer Information', 'State/Province'); INSERT INTO dw_fields VALUES(6, 'Customer Information', 'Zip/Postal Code'); INSERT INTO dw_fields VALUES(7, 'Customer Information', 'Phone Number'); INSERT INTO dw_fields VALUES(8, 'Customer Information', 'Email Address'); INSERT INTO dw_fields VALUES(9, 'Wedding Information', 'Wedding Date'); INSERT INTO dw_fields VALUES(10, 'Wedding Information', 'Approximate Time'); INSERT INTO dw_fields VALUES(11, 'Wedding Information', 'Location'); INSERT INTO dw_fields VALUES(12, 'Wedding Information', 'Reception'); INSERT INTO dw_fields VALUES(13, 'Wedding Information', 'Color Scheme (if applicable)'); INSERT INTO dw_fields VALUES(14, 'Wedding Information', 'Approximate Number Of Guests'); INSERT INTO dw_fields VALUES(15, 'Wedding Information', 'Type Of Ceremony'); Code (markup):
May i ask why you want this? what's your reason to create a real dynamic form. But if you intent to create one, also include options like: min and max length of input validation of input (email, url, text only, numbers only)
Change the database and table name to what you need and try this <?php echo"<table border=1 cellspacing=0 cellpadding=2 style=background:#DDFF66>"; echo "<th colspan=4 >Search Criteria</th>"; echo "<tr>"; echo "<th>User Name</th><th>Week Number</th><th>Project</th><th>Type</th><TR>"; echo" <TD align=middle>Criteria 1</TD><TD align=middle>Criteria 2</TD><TD align=middle>Criteria 3</TD><TD align=middle>Criteria 4</TD><tr>"; ///////////////////////////////////////////////////////////////////////////// //require ('dbconnect.php');normally in another file $db = new mysqli ('localhost','your username','your password','mysql'); if (mysqli_connect_errno()) { $errcode=mysqli_connect_errno(); echo 'Error: could not connect to database. Please try again later.'; exit; } else { $errcode=mysqli_connect_errno(); // echo 'Error No. = '.$errcode ; } ////////////////////////////////////////////////////////////////////////// //require ('dbsqlquery.php');normally in another file $sql="SELECT * FROM `help_keyword`"; //////////////////////////////////////////////////////////////////////// echo $sql; $result=$db->query($sql); $headerdone=false; $num_results = $result->num_rows; echo "<td colspan=4 >No. of records found =$num_results</td>"; echo "</TR>"; echo " </table>"; echo"<table width=1024 border=1 cellspacing=0 cellpadding=0 style=background:#DDFF66>" ; for($j=0; $j<$num_results;$j++) { $i=0; $colname =$result->fetch_assoc();//get column names foreach ($colname as $fieldname => $fieldvalue) {//count columns from here if($headerdone==false){//build headers in bold $UCfieldname=ucfirst($fieldname); echo "<TH>".$UCfieldname."</th>"; $list = ($list.$UCfieldname.",");//build string } if ($fieldname <>"")//add column names to array { $colvalues[$i]=ucfirst($fieldvalue);//Caps on first letter if ($fieldvalue=="") { $colvalues[$i]=0; } $i=$i+1; $numcols=$i;//count columns } }//Headers complete $list=$list." \n";//add linefeed $headerdone=true; echo "<TR>"; for ($addcols=0;$addcols<$numcols;$addcols++) { echo "<td align = middle>".$colvalues[$addcols]."</td>"; $list = ($list.$colvalues[$addcols].","); } }//end of query results $file = fopen("test.csv","w"); //send final constructed string to csv file fputs($file,$list); fclose($file); echo "</table>"; echo"<TR>"; ?> <h2> <?php echo $message?></h2> </form><br /> </body> </html>Seriously I have just tested it and the only change before posting was the username etc.. I hope it works for anyone who needs it. Code (markup):
I am not sure if that is a question or a statement. I'll assume it is a statement and some of it is from PHP admin some is from the web some is from a rather large book on PHP and Mysql I got from my local library PHP and MYsql web development by Luke Welling and Laura Thompson it is about 50 euro As I started PHP about 6 weeks ago I decided to read up copy and manipulate rather than wait for divine intervention to inspire me and donate instant undestanding. This is what we call learning you find someone who knows about the subject and you imitate them and gradually you undrstand and then you innovate and improvise is mise Tubal Cain