Page 1 of 1

Suggestion: CreateInputReset

Posted: Sat Sep 10, 2005 12:52 pm
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";
	}

Re: Suggestion: CreateInputReset

Posted: Wed Sep 14, 2005 4:28 pm
by Ted
Thanks.  This was submitted to svn this afternoon.

Re: Suggestion: CreateInputReset

Posted: Fri Sep 16, 2005 2:17 am
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.

Re: Suggestion: CreateInputReset

Posted: Fri Sep 16, 2005 1:05 pm
by Ted
What should the output look like?

Re: Suggestion: CreateInputReset

Posted: Mon Sep 19, 2005 12:15 am
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;
	}