http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98648

Revision: 98648
Author:   jeroendedauw
Date:     2011-10-01 23:43:52 +0000 (Sat, 01 Oct 2011)
Log Message:
-----------
submission form fixes

Modified Paths:
--------------
    trunk/extensions/Contest/includes/ContestContestant.php
    trunk/extensions/Contest/specials/SpecialContestSignup.php
    trunk/extensions/Contest/specials/SpecialContestSubmission.php

Modified: trunk/extensions/Contest/includes/ContestContestant.php
===================================================================
--- trunk/extensions/Contest/includes/ContestContestant.php     2011-10-01 
23:39:36 UTC (rev 98647)
+++ trunk/extensions/Contest/includes/ContestContestant.php     2011-10-01 
23:43:52 UTC (rev 98648)
@@ -151,11 +151,17 @@
         * 
         * @since 0.1
         * 
+        * @param booolean $addEmptyItem
+        * 
         * @return array
         */
-       public static function getCountriesForInput() {
+       public static function getCountriesForInput( $addEmptyItem = false ) {
                $countries = array();
                
+               if ( $addEmptyItem ) {
+                       $countries[''] = '';
+               }
+               
                foreach ( self::getCountries() as $code => $name ) {
                        $countries["$code - $name"] = $code;
                }

Modified: trunk/extensions/Contest/specials/SpecialContestSignup.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContestSignup.php  2011-10-01 
23:39:36 UTC (rev 98647)
+++ trunk/extensions/Contest/specials/SpecialContestSignup.php  2011-10-01 
23:43:52 UTC (rev 98648)
@@ -63,6 +63,8 @@
                        'user_id' => $user->getId(),
                        'challange_id' => $data['contestant-challangeid'],
                
+                       'country' => $data['contestant-country'],
+               
                        'volunteer' => $data['contestant-volunteer'],
                        'wmf' => $data['contestant-wmf'],
                ) );
@@ -205,7 +207,8 @@
                        'type' => 'select',
                        'label-message' => 'contest-signup-country',
                        'required' => true,
-                       'options' => ContestContestant::getCountriesForInput()
+                       'options' => ContestContestant::getCountriesForInput( 
true ),
+                       'validation-callback' => array( __CLASS__, 
'validateCountryField' )
                );
                
                $fields['contestant-challangeid'] = array(
@@ -285,4 +288,17 @@
                return Sanitizer::validateEmail( $value );
        }
        
+       /**
+        * HTMLForm field validation-callback for country field.
+        * 
+        * @since 0.1
+        * 
+        * @param $value String
+        * @param $alldata Array
+        * 
+        * @return true|string
+        */
+       public static function validateCountryField( $value, $alldata = null ) {
+               return $value !== '';
+       }
 }

Modified: trunk/extensions/Contest/specials/SpecialContestSubmission.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialContestSubmission.php      
2011-10-01 23:39:36 UTC (rev 98647)
+++ trunk/extensions/Contest/specials/SpecialContestSubmission.php      
2011-10-01 23:43:52 UTC (rev 98648)
@@ -90,7 +90,7 @@
                // Check if the user is already a contestant in this contest.
                // If he is, reirect to submission page, else show signup form.
                $contestant = ContestContestant::s()->selectRow(
-                       'id',
+                       null,
                        array(
                                'contest_id' => $contest->getId(),
                                'user_id' => $this->getUser()->getId()
@@ -145,6 +145,8 @@
                $contestant = new ContestContestant( array(
                        'id' => $data['contestant-id'],
                
+                       'country' => $data['contestant-country'],
+               
                        'volunteer' => $data['contestant-volunteer'],
                        'wmf' => $data['contestant-wmf'],
                ) );
@@ -188,6 +190,7 @@
                
                $fields['contestant-country'] = array(
                        'type' => 'select',
+                       'default' => $contestant->getField( 'country' ),
                        'label-message' => 'contest-signup-country',
                        'required' => true,
                        'options' => ContestContestant::getCountriesForInput()
@@ -195,13 +198,13 @@
                
                $fields['contestant-volunteer'] = array(
                        'type' => 'check',
-                       'default' => '0',
+                       'default' => $contestant->getField( 'volunteer' ),
                        'label-message' => 'contest-signup-volunteer',
                );
                
                $fields['contestant-wmf'] = array(
                        'type' => 'check',
-                       'default' => '0',
+                       'default' => $contestant->getField( 'wmf' ),
                        'label-message' => 'contest-signup-wmf',
                );
                


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to