1

我正在编写一个具有表单但提交处理程序不起作用的自定义模块,表单只是提交回自身?非常感谢任何帮助。

我有一个添加来宾自定义表单,并且工作正常。

我网站上的 URL 是:/user/booking_editguest/LBD0413/1 代码如下:

function uUserBookings_editGuestForm($form, &$form_state, $ManageBooking) {
//var_dump($ManageBooking);
$guestSeq = arg(3);
$masterEventCode = $ManageBooking->Contact->{'MasterEventCode'};
$eventCode = $ManageBooking->Contact->{'EventCode'};
$attendeeContact = $ManageBooking->Contact->{'AttendeeContact'};
global $user;
$account = user_load($user->uid);
$memberCode = $account->name;

// booking
$form['booking'] = array(
    //'#type' => 'vertical_tabs',
);

foreach($ManageBooking->guests as $Guest)
    {
    if ($guestSeq == $Guest->{'GuestSeq'} )
        {
            $form['guest_form']['FirstName'] = array(
                '#required' => TRUE,
                '#type' => 'textfield',
                '#title' => t('GUEST FIRST NAME'),
                '#default_value' => $Guest->{'Guest FirstName'}
            );

            $form['guest_form']['Surname'] = array(
                '#required' => TRUE,
                '#type' => 'textfield',
                '#title' => t('GUEST LAST NAME'),
                '#default_value' => $Guest->{'Guest Surname'}
            );

            $form['guest_form']['DietaryRequirements'] = array(
                '#required' => FALSE,
                '#type' => 'textfield',
                '#title' => t('SPECIAL DIETARY REQUIREMENTS'),
                '#default_value' => $Guest->{'Dietary Requirements'}
            );

            $form['guest_form']['CompanyName'] = array(
                '#required' => TRUE,
                '#type' => 'textfield',
                '#title' => t('GUEST COMPANY NAME'),
                '#default_value' => $Guest->{'Company Name'}
            );

            $form['guest_form']['Position'] = array(
                '#required' => TRUE,
                '#type' => 'textfield',
                '#title' => t('GUEST POSITION'),
                '#default_value' => $Guest->{'Attendee Position'}
            );

            $form['guest_form']['Email'] = array(
                '#required' => TRUE,
                '#type' => 'textfield',
                '#title' => t('GUEST EMAIL'),
                '#default_value' => $Guest->{'Guest Email'}
            );

            //MasterEventCode
            $form['guest_form']['masterEventCode'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $masterEventCode
            );
            //EventCode
            $form['guest_form']['eventCode'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $eventCode
            );
            //Member_code
            $form['guest_form']['memberCode'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $memberCode
            );
            //Attendee_Contact
            $form['guest_form']['Attendee_Contact'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $attendeeContact
            );
            //GuestSeq
            $form['guest_form']['GuestSeq'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $Guest->{'GuestSeq'}
            );
            //GuestID
            $form['guest_form']['GuestID'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $Guest->{'Guest Contact Counter'}
            );
            //EventNameDetailsID uniqueidentifier
            $form['guest_form']['EventNameDetailsID'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $Guest->{'EventNameDetailsID'}
            );

            //ID uniqueidentifier
            $form['guest_form']['ID'] = array(
                '#required' => TRUE,
                '#type' => 'hidden',
                '#default_value' => $Guest->{'ID'}
            );

            $form['guest_form']['Submit'] = array(
                '#type' => 'submit',
                '#value' => t('Submit'),
                '#submit' => array('tmsUserBookings_editGuestForm_submit')
            );
        }
    }
return $form;}

function userBookings_editGuestForm_validate($form, &$form_state) {
// Validation logic.
// Don't custom-validate if previous validation errors (still) exist
if (form_get_errors()) return;
// .. Otherwise, process custom form validation goes here }

function userBookings_editGuestForm_submit($form, &$form_state) {
//Get Form variables
$guestFirstname = $form_state['input']['FirstName'];
$guestSurname = $form_state['input']['Surname'];
$guestDietary = $form_state['input']['DietaryRequirements'];
$guestCompany = $form_state['input']['CompanyName'];
$guestPosition = $form_state['input']['Position'];
$guestEmail = $form_state['input']['Email'];
$memberCode = $form_state['input']['Member_code'];
$masterEventCode = $form_state['input']['MasterEventCode'];
$eventCode = $form_state['input']['EventCode'];
$bookerContactCounter = $form_state['input']['Attendee_Contact'];
$guestSeq = $form_state['input']['GuestSeq'];
$guestTitle = $form_state['input']['Title'];
$guestContactCounter = $form_state['input']['GuestID'];
$eventNameDetailsId = $form_state['input']['EventNameDetailsID'];
$id = $form_state['input']['ID'];

//Redirect back to the Booking.
$form_state['redirect'] = '/user/booking_guestupdated';}
4

1 回答 1

0

对于那些使用隐藏文本字段并根据需要进行设置的人,请确保检查输入的值!

于 2013-02-13T15:35:41.137 回答