* 'validation-callback' -- a function name to give you the chance
* to impose extra validation on the field input.
* @see HTMLForm::validate()
+ * 'name' -- By default, the 'name' attribute of the input field
+ * is "wp{$fieldname}". If you want a different name
+ * (eg one without the "wp" prefix), specify it here and
+ * it will be used without modification.
*
* TODO: Document 'section' / 'subsection' stuff
*/
? $info['section']
: '';
- $info['name'] = isset( $info['name'] )
- ? $info['name']
- : $fieldname;
-
if ( isset( $info['type'] ) && $info['type'] == 'file' ) {
$this->mUseMultipart = true;
}
- $field = self::loadInputFromParameters( $info );
+ $field = self::loadInputFromParameters( $fieldname, $info );
$field->mParent = $this;
$setSection =& $loadedDescriptor;
* @param $descriptor input Descriptor, as described above
* @return HTMLFormField subclass
*/
- static function loadInputFromParameters( $descriptor ) {
+ static function loadInputFromParameters( $fieldname, $descriptor ) {
if ( isset( $descriptor['class'] ) ) {
$class = $descriptor['class'];
} elseif ( isset( $descriptor['type'] ) ) {
if ( !$class ) {
throw new MWException( "Descriptor with no class: " . print_r( $descriptor, true ) );
}
+
+ $descriptor['fieldname'] = $fieldname;
$obj = new $class( $descriptor );
/**
* Add a hidden field to the output
- * @param $name String field name
+ * @param $name String field name. This will be used exactly as entered
* @param $value String field value
* @param $attribs Array
*/
$this->mLabel = $params['label'];
}
+ $this->mName = "wp{$params['fieldname']}";
if ( isset( $params['name'] ) ) {
- $name = $params['name'];
- $validName = Sanitizer::escapeId( $name );
-
- if ( $name != $validName ) {
- throw new MWException( "Invalid name '$name' passed to " . __METHOD__ );
- }
-
- $this->mName = 'wp' . $name;
- $this->mID = 'mw-input-' . $name;
+ $this->mName = $params['name'];
+ }
+
+ $validName = Sanitizer::escapeId( $this->mName );
+ if ( $this->mName != $validName && !isset( $params['nodata'] ) ) {
+ throw new MWException( "Invalid name '{$this->mName}' passed to " . __METHOD__ );
}
+
+ $this->mID = "mw-input-{$this->mName}";
if ( isset( $params['default'] ) ) {
$this->mDefault = $params['default'];
class HTMLHiddenField extends HTMLFormField {
public function __construct( $params ) {
parent::__construct( $params );
- # forcing the 'wp' prefix on hidden field names
- # is undesirable
- $this->mName = substr( $this->mName, 2 );
# Per HTML5 spec, hidden fields cannot be 'required'
# http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#hidden-state
// create the form, which will also be used to execute a callback to process incoming form data
// this design is extremely dubious, but supposedly HTMLForm is our standard now?
- $form = new HTMLForm( array( 'clear' => array( 'class' => 'HTMLHiddenField', 'default' => true ) ), 'clearStashedUploads' );
+ $form = new HTMLForm( array(
+ 'Clear' => array(
+ 'type' => 'hidden',
+ 'default' => true,
+ 'name' => 'clear',
+ )
+ ), 'clearStashedUploads' );
$form->setSubmitCallback( array( __CLASS__, 'tryClearStashedUploads' ) );
$form->setTitle( $this->getTitle() );
$form->addHiddenField( 'clear', true, array( 'type' => 'boolean' ) );