zf2选择框发送邮件中的代码和值

I am working with ZF2 Select boxes

I have set the options from the controller and everything is working fine. I choose the option and press select, the code goes to the action in the post values.

I want a little bit more; along with the code I want to pass the value too.

example: I have the following select options

The select box is for choosing the gender of the user; The corresponding action is "AddUserProfileForm" on confirming the action called is "AddUserProfile"

<select name="user_gender_code">
<option value="M">Male</option>
<option value="F">Female</option>
</select>

I want to pass both the code "M" and the corresponding value "Male" across the post This will ensure that in the subsequent form I have the Code to write to the Database and the Value to Disply on the screen without performing a database read.

The only option I can think of is to build the code as below

<select name="user_gender_code">
<option value="M~Male">Male</option>
<option value="F~Female">Female</option>
</select>

This will ensure that "M~Male" is sent across a post and then I split the value "M" & "Male" separately.

I am not setting the valueOptions in the form; In the form they are empty, I use a function in the controller to read the database and set the valueOptions;

Does someone have a better option; I can create a hidden form element "user_gender_name" and if this is populate with the value of the option selected before the post it will make my job easier and more clean

Does anyone know how to do this? Thank you in advance for your time

AddUserProfileForm - Code

    $this->viewModel = $this->getViewModel( );
    $EnvironmentTable = $this->getServiceLocator ( )->get( 'UserTable' );
    $post = $this->request->getPost( );
    //Get Route Variable Section
    //  ****Get Any Route Variable you need over here


    //End Get Route Variable Section

    $form = $this->getServiceLocator ( )->get( 'AddUserProfileForm' );
    //Get Table Records Section
    //  ****Get Any Table Records you need over here


    //End Get Table Records Section

    $form->get( 'user_gender' )->setValueOptions( $this->getLookupGenderList( ) );
    $this->viewModel->AddUserProfileForm = $form;
    //Set View Variables Section
    //  ****Define other view variables over here


    //End Set View Variables Section

    return $this->viewModel;

AddUserProfile - Code

$this->viewModel = $this->getViewModel( );
$post = $this->request->getPost( );
//Get Route Variable Section
//  ****Get Any Route Variable you need over here

//End Get Route Variable Section

$fromForm = $this->getServiceLocator ( )->get( 'AddUserProfileForm' );
//Bind Form Section
//  ****Bind the form with the Table Record over here

//End Bind Form Section

Unless I'm completely misunderstanding the question, your select element already contains the options as an array of key/value pairs, you only need to get the selected value, and then use it as key in the options array which will give you the name of the selected option ...

if ($form->isValid()) {
    // get the element
    $selectElement = $form->get('selectElement');
    // get the selected value
    $selectValue   = $selectElement->getValue();  // 'M'
    // get the select options
    $selectOptions = $selectElement->getValueOptions(); // array('M' => 'Male, 'F' => 'Female');
    // get option name using selected value as key in options array 
    $genderName = $selectOptions[$selectValue];  // 'Male'
}

The easiest solution I have is to concatenate the code & value in the code; when the post is done, the concatenated code is sent across. We can split on the separator and get both the values.