Suggestion: CreateInputReset

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
mbvdk
Forum Members
Forum Members
Posts: 43
Joined: Wed Jun 08, 2005 3:30 pm

Suggestion: CreateInputReset

Post by mbvdk »

While working on my FAQ/Q&A module I nedded a reset-buton, so I tried CreateInputReset(), but this was not available, so I created it.

Here is the code, it should be placed in class.module.inc.php

Code: Select all

	/**
	 * Returns the xhtml equivalent of a reset button.  This is basically a nice little wrapper
	 * to make sure that id's are placed in names and also that it's xhtml compliant.
	 *
	 * @param string The id given to the module on execution
	 * @param string The html name of the button
	 * @param string The predefined value of the button, if any
	 * @param string Any additional text that should be added into the tag when rendered
	 */
 	}
	function CreateInputReset($id, $name, $value='', $addttext='')
	{
		$text = '<input type="reset" name="'.$id.$name.'" value="'.$value.'"';
		if ($addttext != '')
		{
			$text .= ' '.$addttext;
		}
		$text .= ' />';
		return $text . "\n";
	}
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: Suggestion: CreateInputReset

Post by Ted »

Thanks.  This was submitted to svn this afternoon.
trick

Re: Suggestion: CreateInputReset

Post by trick »

While were at it, can I suggest CreateLabel? The current way of doing forms causes accessibility issues, and correcting it is quite a pain.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: Suggestion: CreateInputReset

Post by Ted »

What should the output look like?
trick

Re: Suggestion: CreateInputReset

Post by trick »

Well, in html terms a form usually looks something like this:



My Form
Foo:

Bar:



According to the specs and the DTD a label MUST have a for attribute and it must have a corresponding id on the form control (like input | textarea | button | select ).

A label is allowed to include any inline content (except another label) or PCDATA (text). I've actually never seen anyone put anything but text in a label but it is allowed. If you just wanted it to be simple you can have 1 function that creates "$text" or you could have 1 to make a "" and another 1 for a "". Personally I would like the first because it's simpler and I have never had use for putting complicated stuff inside a label. for example:

Code: Select all

/**
* Returns the xhtml equivalent of a label.  This is basically a nice little wrapper
*
* @param string The id given to the module on execution
* @param string The html for of the label
* @param string The contents of the label
* @param string Any additional text that should be added into the tag when rendered
*/
}
function CreateLabel($id, $for, $value='', $addtext='')
{
return "<label for='$id$for' $addtext >$value</label>\n"
}
More importantly you need change the CreateInputText and the other functions to include an id parameter. I.e.

Code: Select all

function CreateInputText($id, $name, $value='', $size='10', $maxlength='255', $addttext='', $idparam='')
	{
		$value = str_replace('"', '"', $value);
		$text = '<input type="text" name="'.$id.$name.'" value="'.$value.'" size="'.$size.'" maxlength="'.$maxlength.'"';
		if ($addttext != '')
		{
			$text .= ' ' . $addttext;
		}
		if ($idparam != '')
		{
			$text .= " id='$id$idparam'";
		}
		$text .= " />\n";
		return $text;
	}
Post Reply

Return to “Developers Discussion”