GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum > PHP Code Library
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Jan-2003, 20:45
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Junior Member
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road

[Class] Generate Forms Without Using HTML!


PHP Code:

// Name: Form Generator
// Version: 1.0
// Author: Elmseeker
// Description: Generates HTML Forms without cluttering your PHP.
// either echo these functions directly like:
// echo $frm->newform( "POST", "myformproccessor.php" );
// or place them into a variable and echo the variable like:
// $test = $frm->newform( "POST", "myformproccessor.php" );
// echo $test;
// both ways work fine...Enjoy!
// Type: Class

class doform {

// Usage:
// $frm = new doform();

function newform( $method, $action ) {

$text = "<form method=\"".$method."\" action=\"".$action."\">";

return($text);

// Usage:
// $frm->newform( "POST", "myformproccessor.php" );

}
 
function endform() {

$text =  "</form>";

return($text);

// Usage:
// $frm->endform();

}
 
function text( $name ) {

$text = "<input type=\"text\" name=\"".$name."\">";

return($text);

// Usage:
// $frm->text("testing");
// creates a text box named testing

}
 
function pass( $name ) {

$text = "<input type=\"password\" name=\"".$name."\">";

return($text);

// Usage:
// $frm->pass("testing");
// creates a password box named testing

}
 
 
function radio( $name, $info ) {

foreach($info as $value) {
$text = $text.$value." <input type=\"radio\" name=\"".$name."\" value=\"". $value ."\"></input>";
}
 
return($text);

// Usage:
// $frm->radio( test, array("v1", "v2", "v3", "v4"));
// where test is the name of the key and v1-v4 are the values, completely
// expandable to hold as many values as needed...

}
 
 
function checkbox( $info ) {

foreach( $info as $key=>$value) {
$text = $text.$value." <input type=\"checkbox\" name=\"".$key."\" value=\"". $value ."\"></input>";
}
 
return($text);

// Usage:
// $frm->checkbox(array("test1"=>"v1", "test2"=>"v2", "test3"=>"v3", "test4"=>"v4"));

}
 
function select( $name, $info, $size ) {

$text = "<SELECT NAME=\"".$name."\" size=".$size.">";

foreach( $info as $value ) {
$text = $text."<OPTION>".$value;
}
 
$text = $text."</SELECT>";

return($text);
// Usage:
// $frm->select( test, array("v1", "v2", "v3", "v4"), 4);
// where test is the name of the key and v1-v4 are the values, completely
// expandable to hold as many values as needed...$size is how many to
// display on scrren without scrolling. Select Boxes...

}
 
function combo( $name, $info ) {

$text = "<SELECT NAME=\"".$name."\">";

foreach( $info as $value ) {
$text = $text."<OPTION>".$value;
}
 
$text = $text."</SELECT>";

return($text);

// Usage:
// $frm->combo( "test", array("v1", "v2", "v3", "v4"));
// where test is the name of the key and v1-v4 are the values, completely
// expandable to hold as many values as needed...Drop Down boxes...

}
 
function textarea( $name, $row, $col ) {

$text = "<TEXTAREA NAME=\"".$name."\" ROWS=".$row." COLS=".$col."></textarea>";

return($text);

// Usage:
// textarea( "testing", 6, 60 );
// Will create a textarea 60 colums wide and 6 rows high.

}
 
function submit( $name, $value ) {

$text = "<INPUT TYPE=submit NAME=\"".$name."\"VALUE=\"".$value."\"></INPUT>";

return($text);

// Usage:
// $frm->submit("submiter", "Submit Me!");
// Will create a submission button named submiter that
// says Submit Me!
}


function fclear( $name ) {

$text = "<INPUT TYPE=reset VALUE=\"".$name."\"></INPUT>";

return($text);

// Usage:
// $frm->fclear( "Reset Form" );
// Creates a reset button that says Reset Form...

}

} 


Last edited by Elmseeker : 15-Jan-2003 at 21:01.
  #2  
Old 15-Jan-2003, 21:22
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
This is priceless...

Just a few notes for your list of things 'yet' to do with this class:

Stuff that really matter (and usually optional) -
Code:
selected="true" checked="true" value="default" id="idname"
and friends...

Can you split this into a new thread?

I would rename the public methods to something more 'user-friendly', something like
PHP Code:

<?php
$frm->InsertTextField();
$frm->InsertPasswordField();
// etc...
?>


And since you're concatenating the vars, I would suggest using single quotes throughout, it's also good habit to get into...
  #3  
Old 15-Jan-2003, 21:45
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Junior Member
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road
selected="true"
and
checked="true"

Will be almost impossible to code without making the argument list for the function overly long.

As for renaming the functions, the way you describe would kind of defeat the purpose of the class wich is partially to save on keystrokes, I tried to keep the names short and simple for just that purpose...
  #4  
Old 16-Jan-2003, 21:00
Charlie Charlie is offline
New Member
 
Join Date: May 2002
Location: Minnesota, USA
Posts: 24
Charlie is an unknown quantity at this point
So how would you choose where to send the info (i.e. via email)?
  #5  
Old 17-Jan-2003, 08:27
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Junior Member
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road

RE; Forms without HTML!


You send it to your form proccessing script as normal and access the variables the same way...so if I had a form set up like:

PHP Code:

$frm = new doform();

echo $frm->newform("POST", "$PHP_SELF?page=logproc");// "<form method=\"post\" action=$PHP_SELF?page=logproc>
echo "<TABLE width=400 border=0 align=center cellpadding=2 cellspacing=0 valign=top>
<TR><TH ALIGN=center COLSPAN=2>Login<BR></TH></TR>";

echo "<TR><TD ALIGN=left>Username: </TD><TD ALIGN=center> ".$frm->text("name");
echo "</TD></TR>
<TR><TD ALIGN=left>Password: </TD><TD ALIGN=center> ";
echo $frm->pass("pass1");
echo "</TD></TR>
<TR><TD ALIGN=center>".$frm->fclear("Clear Form")."
</TD>
<TD ALIGN=center>".$frm->submit("submital", "Submit")."
</TD></TR>
</table>"; 



I would have a script within this script file to proccess the information sent by the script as you normall would for any form. I can access the elements something like:

echo $_POST["name"]."<BR>".$_POST["pass"];

and they can either be echoed or sent into an email or renamed with something like:

$name = $_POST["name"];

Which will now allow me to access tham as I would any other variable...Enjoy!
  #6  
Old 10-Mar-2003, 11:28
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Elmseeker is there anywhere where you are using this so I can see it in action?
  #7  
Old 11-Mar-2003, 13:05
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Junior Member
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road
Quote:
Originally posted by jrobbio
Elmseeker is there anywhere where you are using this so I can see it in action?


But of course, didn't think I'd write it and not be using it myself do ya? hehe...

http://www.kid-stop.com/

both the sign-up and the login forms use this class. :)
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing to HTML document in C++. markov C++ Forum 5 21-Jan-2004 08:38
html to php tenaki Web Design Forum 17 28-Oct-2003 17:18
Forms in multiple windows ukrspp21 MySQL / PHP Forum 0 02-Oct-2003 12:07

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:10.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.