For beginner form generate code

Started on the old forum in August 2011 · view the original in the archive · old links redirect here

6 replies · 602 views · started 15 years ago · 1 min read

5 participants
andrew3008 Developer · 102 posts #1

connect.php

<?php

	class connect
	{
		
//$x = array("text-2","password-2","file-1","submit-1","lable-2");

		function createform($method,$action,$enctype,$x)

		{

echo $str = "<form method='".$method."' action='".$action."' enctype='".$enctype."'>";
		
		
foreach($x as $k=>$v)
{
	$vdata = explode("-",$v);
	
	if($vdata[0]=="text")
	{
		$i=1;
		while($i<=$vdata[1])
		{
			$this->createtext("","","20",$vdata[0],1,"");$i++;
			echo "<br />";
			echo "<br />";
		}
	}

	else if($vdata[0]=="password")
	{	
		
		$i=1;
		while($i<=$vdata[1])
		{
			$this->createtext("","","",$vdata[0],6,"");$i++;
			echo "<br />";
			echo "<br />";
		}
	}

	else if($vdata[0]=="submit")
	{
		$i=1;
		while($i<=$vdata[1])
		{
			$this->createtext("","Enter","",$vdata[0],1,"");$i++;
			echo "<br />";
			echo "<br />";
		}
	}
	else if($vdata[0]=="file")
	{
		$i=1;
		while($i<=$vdata[1])
		{
			$this->createtext("","","",$vdata[0],4,"");$i++;
			echo "<br />";
			echo "<br />";
		}
	}

	else
	{}

}

echo $str="</form>";

//echo $str;

		}

		function createtext($name,$value,$maxlength,$type,$fortype,$option)
		{
			if($fortype==1)
			{
				
				$str = "<input type='".$type."' maxlength='".$maxlength."' value='".$value."' name='".$name."' id='".$name."'  class='".$name."' />";
				
			}
			else if($fortype==2)
			{
				
				$str = "<textarea maxlength='".$maxlength."' name='".$name."' id='".$name."'  class='".$name."'> ".$value."</textarea>";
				
			}
			else if($fortype==3)
			{
				
				$str = "<select name=".$name.">";
				if(count($option)>0)
				{
					foreach($option as $k=>$v)
					{
						$vdata = explode("-",$v);
						$str.="<option value=".$vdata[0].">".$vdata[1]."</option>";
					}
					
				}
				$str.= "</select>";
			}

			else if($fortype==4)
			{
				$str = "<input type='".$type."' value='".$value."' name='".$name."' id='".$name."'  class='".$name."' />";
			}
			else
			{
				$str = "<input type='".$type."'  value='".$value."' name='".$name."' id='".$name."'  class='".$name."' />";
			
			}
			
			echo $str;	
		}
		
		
				
		
		
		}
		$obj=new connect;

?>

test.php

<?php
	// include_once("connect.php");
	
	
	
	
$x = array("text-2","password-2","file-1","submit-1","lable-2");
$obj->createform("post","action.php",5,$x);
?>

php masters make this code better

subzero Super moderator Fellow · 3,954 posts #2

You want it cleaner or load faster then it will not do ?

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

CreativityKills Lead · 833 posts #3

Usually its best to use plain text/html, form generators are tricky business. If ure using a framework that has been component unit tested fine, else dont be lazy.

something else Fellow · 2,296 posts #4

For a beginner this would probably be to confusing lol

andrew3008 Developer · 102 posts #5

i start learning php 1 week bfore jus i tried this so better thought share and get feedback and make it better

subzero Super moderator Fellow · 3,954 posts #6

i like adding to the page other then adding to MySql.

Think of noobs i know have 159 database to control one site and they asking me why there site loads is so high lmao !

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

kei_ki7 Senior · 431 posts #7

I guess, class makes difficult for beginners.

Did I help you? You can help me too Your donations will help me finance my studies.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close