Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Site Goodies > Saline's Brain Teasers
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-24-2003, 07:54 PM   #1 (permalink)
saline
I am red.
 
saline's Avatar
 
Join Date: Feb 2003
Location: Cleveland, OH
Posts: 139
saline is on a distinguished road
What a waste of time!

Hey everybody, do you know what I love? The internet. Know why? Because it's cool. I've loved the internet (or the intarweb depending on who you ask) for years now. It's so cool, it's a completely new world conainted within our own, larger than your antfarm but still controllable, sweet. I started HTML in ninth grade when I should have been paying attention to my Biology teacher (bad idea on my part). I spent hours learning HTML and becoming a better designer and at the time I wasen't really much of a programmer so I didn't mind all the repetative cutting and pasting and sitting there for hours doing the same thing over and over, it was still fun.

Then I started learning more, I learned to program and learned about CGI scripts and how big webpages worked and I realized I was the biggest tool in the world. But I've got a real big tolerance for self deprecation so I stayed the course and created the largest website I had ever administered before. It was a site for a small magazine (or zine). The person who runs the magazine wanted a place for news, back issues, guidelines for submitting and a way for people to subscribe. I was like, ok easy, uh huh got an idea, sure no problem and ok yeah I can do something for that. Next thing you know I'm neck deep in sloppy HTML and like two weeks behind schedule and I'm having fits over graphics and spacing and getting everything to display right.

Long story short, I did it, it took days and weeks and months but over time I got up an alpha and told the person I was working for "yay I'm done"! Then I did the sneaky procrastinator trick and kept working behind the scenes, without telling the magazine person, to get everything right. I updated the entire site, made the HTML completely sealed up as best I knew, solidified the few scripts I used and just generally ensured it would work for the majority of users (your mileage may vary).

I kept updating it for them and made changes over time and added a section or two and generally things go pretty well with the site. But very little changed in the way I was creating pages I had a template which I would go and fill in, by hand, every time. It was no fun any more and I was so tired of it my desire to update dwindled to almost nothing.

Recently I wrote a program to automate one of the most mind numbing tasks. On the pages with back issues we list the people who wrote for the issue each person in a different cell of a table. Well the magazine is a poetry magazine so the pieces aren't long, and it's a pretty big magazine so there's potentially six to seven people on every two pages. So it's a big table and was a big waste of time the way I was doing it. So I just took the format that I usually get the list of people in, and wrote a program to produce the webpage and write it to a file.

I'm working on making it a CGI script so I don't even have to do anything and I can finally get back to cataloging the bits of food I find on the floor of my room.

Anyway, the teaser for this week is to make my life easier! Or at least somebodies life easier. Find some tedious task and automate the sucker. There's lots of stuff you could do with HTML:

1) Write a program to search for a certain string and replace it within a text file (not just for HTML), or a group of text files.

2) Write a program which automates the creation of external Cascading Style Sheets which prompts the user to enter values for the background color, font, text size and other generally specified things.

3) Maybe a program that alerts the user of any potentially un-closed tags within an HTML document.

4) Or a program which creates tables where the user can specify the number of rows and columns and then go fill them in.

All of these things remove the grunt work from webdesign which is so nice after years and years of control c-ing and control v-ing.

This teaser requires some experience with HTML and will most likely require you know how to create and write to files. I can help with both HTML and making files in C++, python, Perl (but may have difficulty in Perl as some of you may have noticed) and I might be able to fake it in Visual Basic as well.

They're short, they're sweet and they're potentially super useful, lets see what everyone can come up with!

I'll post mine some time soon.
__________________
saline is offline   Reply With Quote
Old 03-25-2003, 12:57 PM   #2 (permalink)
pngwyn
Registered User
 
pngwyn's Avatar
 
Join Date: Mar 2003
Location: Boise, Idaho
Posts: 4
pngwyn is on a distinguished road
Send a message via ICQ to pngwyn Send a message via AIM to pngwyn Send a message via Yahoo to pngwyn
Lightbulb Off Topic but makes PHP Design Easier

I have begun writing a (IMO) useful PHP script that I like to call 'Fast Forms.' As the name implies it is a script that you can include in your PHP scripts for quick generation and validation of HTML Input Forms.

It isn't quite complete and I am going to write a component that will allow for verification checks on fields, IE a US Zip code field contains 5 numbers, email address looks like an e-mail address, phone numbers are only numeric, etc...

If there is enough interest I can post the updates that I will be making over the next several weeks.

The comments at the tail end of the script contain examples on usage. You can look at the specific functions for variable examples.

Feel free to modify but I would appreciate the credit and/or improvements to be mailed back.

DISCLAIMER: The code has not been "beautified", yet.

PHP Code:
<?
/*******************************
fastForms v0.50
--- by Nathan Cook <ncook@pcsedu.com>
*******************************/

/*******************************
• FileField Function Needs Flesh
• FileField Behind the scenes needs
  planned and written

A set of functions to rapidly
create, validate and provide
user feedback for HTML forms.
*******************************/

if(!$font) { $font "<font face=verdana,arial,helvetica size=2>"; }
$PHP_SELF $_SERVER[PHP_SELF];

// Initializes the form, creates global variables to track required vars, track errors,
// report errors and begins the buffer to draw the table.  $$formname, form print buffer
function startForm($title$name$bgcolor$postto$target$width$cellpadding$cellspacing$border$encType 0)
{
    global 
$form$formName$font;
    if(
$encType == '1') { $encPrint "enctype=\"multipart/form-data\""; } else { unset($encPrint); }
    if(
$border != 0) {
        
$form .= "<table cellpadding=$border cellspacing=0 border=0 bgcolor=#000000><tr><td>\n";
    }
    
$formName $name;
    if(
$target != "") { $targetPrint "target=$target"; } 
    
$form .= "<table bgcolor=$bgcolor border=0 width=$width cellpadding=$cellpadding cellspacing=$cellspacing>\n";
    
// create <form> with $postto, $targetPrint
    
$form .= "<form $encPrint method=POST action=".$postto." $targetPrint>\n";
    
// Draw header for table proclaiming the $title
    
$form .= "<tr>\n\t<td colspan=2>$font  <font size=+1>";
    if(
$title != ""$form .= "<b>$title</b><br>";
    
$form .= "<hr size=1 width=99%></td>\n</tr>\n";
}
function 
reqd($required$name$label) {
    global 
$form$formName$font$errorArr;
    
hidField('required[]'$name);
    if(
$errorArr != "") {
        if(
array_search($name$errorArr)) {
            
$label '<font color=#FF0000>'.$label.'</font>';
        }
    }
    
$label '<b>'.$label.'</b>';
    return 
$label;
}
function 
heading($title$bold)
{
    global 
$form$formName$font;
    if(
$bold == '1') { $text "<b>$title:</b>"; } else { $text $title; }
    
$form .= "<tr>\n\t<td colspan=2 height=22>$font $text</td>\n</tr>\n";
}
// Draws a text field based on the variables supplied.
function textField($label$name$size$maxlength$required '0'$disabled '0')
{
    global 
$form$formName$font;
    if(
$required == '1') { $label reqd($required$name"$label"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }
    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $label </td>\n";
    
    
// Print Field in second cell
    
$form .= "\t<td>$font <input type=text name=$name value=\"".$_REQUEST[$name]."\" size=$size maxlength=$maxlength $dis></td>\n";
    
    
$form .= "</tr>\n";
}
function 
dateInput($label$name$required '0'$disabled '0')
{
    global 
$form$formName$font;
    if(
$required == '1') { $label reqd($required$name"$label"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }

    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $label </td>\n";
    
    
$nameMon $name."Mon";
    
$nameDay $name."Day";
    
$nameYear $name."Year";
    
// Print Field in second cell
    
$form .= "\t<td>$font <input type=text name=".$name."[] value=\"".$_REQUEST[$name][0]."\" size=2 maxlength=2 $dis>&nbsp;/&nbsp;\n";
    
$form .= "\t$font <input type=text name=".$name."[] value=\"".$_REQUEST[$name][1]."\" size=2 maxlength=2 $dis>&nbsp;/&nbsp;\n";
    
$form .= "\t$font <input type=text name=".$name."[] value=\"".$_REQUEST[$name][2]."\" size=4 maxlength=4 $dis></td>\n";
    
    
$form .= "</tr>\n";
}
function 
phoneField($label$name$required '0'$disabled '0')
{
    global 
$form$formName$font;
    if(
$required == '1') { $label reqd($required$name"$label"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }

    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $label </td>\n";
    
    
// Print Field in second cell
    
$form .= "\t<td>$font (<input type=text name=".$name."[] value=\"".$_REQUEST[$name][0]."\" size=3 maxlength=3 $dis>)&nbsp;\n";
    
$form .= "\t$font <input type=text name=".$name."[] value=\"".$_REQUEST[$name][1]."\" size=3 maxlength=3 $dis>&nbsp;-&nbsp;\n";
    
$form .= "\t$font <input type=text name=".$name."[] value=\"".$_REQUEST[$name][2]."\" size=4 maxlength=4 $dis></td>\n";
    
    
$form .= "</tr>\n";
}
function 
passField($label$name$size$maxlength$required '0'$disabled '0')
{
    global 
$form$formName$font;
    if(
$required == '1') { $label reqd($required$name"$label"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }

    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $label </td>\n";
    
    
// Print Field in second cell
    
$form .= "\t<td>$font <input type=password name=$name value=\"".$_REQUEST[$name]."\" size=$size maxlength=$maxlength $dis></td>\n";
    
    
$form .= "</tr>\n";
}

// Draws a checkbox field based on the variables supplied
function checkField($label$name$value)
{
    global 
$form$formName$font;

    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font -&nbsp;$label</td>\n";
    
    
// Print Field in second cell
    
if(isset($_REQUEST[$name])) { $checked "checked"; } else { unset($checked); }
    
$form .= "\t<td>$font <input type=checkbox name=$name value=\"$value\" $checked></td>\n";
    
    
$form .= "</tr>\n";
}

// Draws a hidden field based on the variables supplied
function hidField($name$value)
{
    global 
$form$formName$font;
    
// print field for hidden value and name
    
$form .= "\t<input type=hidden name=\"$name\" value=\"$value\">\n";
}

// Draws a file upload field based on the variables supplied
function fileField($label$name$filesize$required '0')
{
    global 
$form$formName$font;
    if(
$required == '1') { $label reqd($required$name"$label"); }

    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $label</td>\n";
    
    
// Print Field in second cell
    
$form .= "\t<td>$font <input type=file name=$name></td>\n";
    
$form .= "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$filesize\">";
    
$form .= "</tr>\n";
}

// Begins a set of radio fields based on the variables supplied
function radioField($label$name$none '0'$required '0'$disabled '0')
{
    global 
$form$formName$font$nonoption;
    if(
$required == '1') { $label reqd($required$name"$label"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }
    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $label</td>\n";
    
    
// begin cell for radio buttons
    
if($none == '1') { 
        
$form .= "\t<td>$font <input type=radio name=$name value=\"0\" $dis>None</td>\n";
        
$form .= "</tr>\n";
    } 
    
    
$nonoption $none;
}

// Adds options to the radio fields based on the variables supplied
function radioOption($label$name$value)
{
    global 
$form$formName$font$nonoption;
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }
    
// Draw Table Row
    
if($nonoption == '1') { 
        
$form .= "<tr>\n";
        
// Print $label in first cell
        
$form .= "\t<td width=75%>$font &nbsp;</td>\n";
    }    
    
// begin cell for radio buttons
    
if($_REQUEST[$name] == $value) { $selected "checked\n"; } else { unset($selected); }
    
$form .= "\t<td>$font <input type=radio name=$name value=\"$value\" $selected $dis>$label</td>\n";

    
$form .= "</tr>\n";
    
$nonoption '1';
}

// Adds options to the select field based on the variables supplied
function selectOption($label$value$name)
{
    global 
$form$formName$font, $$name;
    
// Detect pre-selected fields
    // Creates/Appends to a string the options with default values
    
if($_REQUEST[$name] == $value) { $selected "selected\n"; } else { unset($selected); }
    $
$name .= "\t\t\t<option value=\"$value\" $selected>".$label."</option>\n";
}

// Initializes a select field based on the variables supplied
// YOU MUST DEFINE ALL SELECT OPTIONS BEFORE DEFINING FIELDS
function selectField($title$name$size '1'$required '0'$disabled '0')
{
    global 
$form$formName$font, $$name;
    if(
$required == '1') { $title reqd($required$name"$title"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }
    
// create row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75%>$font $title</td>\n";
    
    
// second cell: <select $name $size>
    
$form .= "\t<td>";
    
$form .= "$font\n\t\t <select name=$name size=$size $dis>\n";
    
$form .= $$name;
    
$form .= "\n\t\t</select>\n";
    
$form .= "\t</td>\n";

    
$form .= "</tr>\n";
}

// Draws a text area based on the variables supplied
function areaField($label$name$rows$cols$wrapstyle$required '0'$disabled '0')
{
    global 
$form$formName$font;
    if(
$required == '1') { $label reqd($required$name"$label"); }
    if(
$disabled == '1') { $dis 'disabled'; } else { unset($dis); }

    
// Draw Table Row
    
$form .= "<tr>\n";
    
// Print $label in first cell
    
$form .= "\t<td width=75% valign=top>$font $label</td>\n";
    
    
// Print Field in second cell
    
$form .= "\t<td>$font <TEXTAREA name=$name cols=$cols rows=$rows wrap=$wrapstyle $dis>".$_REQUEST[$name]."</textarea></td>\n";
    
    
$form .= "</tr>\n";
}

// Ends Form, adds hidden fields for passing the global arrays.
function endForm($button$border)
{
    global 
$form$formName$font;
    
// print submit button
    
$form .= "<tr>\n\t<td colspan=2 align=right>\n\t\t<hr size=1 width=99%>\n\t\t$font \n\t\t<input type=submit name=submit value=\"$button\">\n\t</td>\n</tr>\n";
    
// close table
    
$form .= "</table>\n";
    
    
//if($border != 0) {
    
$form .= "</td></tr></table>\n";
    
//}
}

// parses through the global arrays to validate form fields
function validateForm()
{
    global 
$form$formName$font$errorArr$errorStr$valid;
    if(
count($_REQUEST[required])) { 
        foreach(
$_REQUEST[required] as $field) {
            if((
$_REQUEST[$field] == "")||($_REQUEST[$field] == '0')) { 
                
$errorArr .= ",$field";
                if(!
$errorStr) { $errorStr "Complete the Bold Red fields to continue."; }
            }
        }
    }
    if(
$errorArr != "") {
        
$errorArr explode(","$errorArr);
    } else { 
        
$valid '1';
    }
}
function 
errorOutput($errorStr)
{
    global 
$form$formName$font;
    if(
$errorStr != "") {
        
$form .= "<tr>\n\t<td colspan=2 align=center>$font <font color=#FF0000><b>$errorStr</b></font></font></td>\n</tr>\n";
    }
}

/* Example ****************************
if($_REQUEST[submit]) { validateForm(); }

$formTitle = 'Testing';
$formName = 'test';
$bgcolor = '#DDDDDD';
$postto = $PHP_SELF;
$target = '';
$width = '350';
$cellpadding = '2';
$cellspacing = '0';
$border = '1';

startForm($formTitle, $formName, $bgcolor, $postto, $target, $width, $cellpadding, $cellspacing, $border);
errorOutput($errorStr);
textField('First Name', 'fname', '20', '40', 1);
textField('Last Name', 'lname', '20', '40', 1);
heading('Your Organization', 0);
checkField('School', 'school', '1');
checkField('YMCA', 'ymca', '1');
checkField('Boys & Girls Club', 'bgca', '1');
radioField('Sex', 'sex', '0', '1');
radioOption('Male', 'sex', 'male');
radioOption('Female', 'sex', 'female');
selectOption('<- Select One ->', '0', 'jobtitle');
selectOption('Programmer', 'prog', 'jobtitle');
selectOption('SysAdmin', 'sysad', 'jobtitle');
selectOption('Developer', 'develop', 'jobtitle');
selectField('Job Title', 'jobtitle', '1', '1');
areaField('Notes', 'notes', '4', '20', 'virtual', '1');
endForm('Submit', 1);

print($form);

********************************** */
?>
__________________
pngwyn is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using IsDate( ) to check for a Time value shs MS Technologies ( ASP, VB, C#, .NET ) 1 09-09-2004 12:03 PM
estimating processing time astromonkey Standard C, C++ 6 06-25-2004 09:17 AM
network time synchronisation in java bossebo Java 1 06-21-2004 05:17 PM
Adjusting date() function for time zones Epsilon PHP 1 02-27-2004 02:55 AM
Assign value to a variable depending on time AOD PHP 10 02-12-2003 03:06 PM


All times are GMT -8. The time now is 08:50 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle