function createForm()
 {
     $f = new Am_Form();
     $g = $f->addGroup('newsletter')->setLabel(___('Choose Newsletters'));
     $g->addRule('required', 'This field is required');
     $g->setSeparator("<br />\n");
     foreach ($this->lists as $l) {
         $title = $l->title;
         if ($l->desc) {
             $title .= " - " . $l->desc;
         }
         $el = $g->addCheckbox($l->pk())->setContent($title);
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
             $el->setAttribute('checked');
         }
         // checked by default
     }
     $f->addText('name', array('size' => 40))->setLabel(___('Name'))->addRule('required', 'This field is required');
     $f->addText('email', array('size' => 40))->setLabel(___('E-Mail Address'))->addRule('required', 'This field is required')->addRule('callback', "Please enter valid e-mail address", array('Am_Validate', 'email'))->addRule('callback', "There is a user registered with this e-mail address. Please login to manage your subscriptions", array($this, 'checkUserEmail'));
     $f->addSubmit('do', array('value' => ___('Subscribe')));
     return $f;
 }
예제 #2
0
파일: paymill.php 프로젝트: grlf/eyedock
    public function createForm($label, $cc_mask = null)
    {
        $form = new Am_Form('cc-paymill');
        $name = $form->addGroup()->setLabel(___("Cardholder Name\n" . 'cardholder first and last name, exactly as on the card'));
        $name->addRule('required', ___('Please enter credit card holder name'));
        $name_f = $name->addText('cc_name_f', array('size' => 15, 'id' => 'cc_name_f'));
        $name_f->addRule('required', ___('Please enter credit card holder first name'))->addRule('regex', ___('Please enter credit card holder first name'), '|^[a-zA-Z_\' -]+$|');
        $name_l = $name->addText('cc_name_l', array('size' => 15, 'id' => 'cc_name_l'));
        $name_l->addRule('required', ___('Please enter credit card holder last name'))->addRule('regex', ___('Please enter credit card holder last name'), '|^[a-zA-Z_\' -]+$|');
        $cc = $form->addText('', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22, 'id' => 'cc_number'))->setLabel(___('Credit Card Number'), ___('for example: 1111-2222-3333-4444'));
        if ($cc_mask) {
            $cc->setAttribute('placeholder', $cc_mask);
        }
        $cc->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/');
        class_exists('Am_Form_CreditCard', true);
        // preload element
        $expire = $form->addElement(new Am_Form_Element_CreditCardExpire('cc_expire'))->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year'));
        $code = $form->addPassword('', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4, 'id' => 'cc_code'))->setLabel(___('Credit Card Code'), sprintf(___('The "Card Code" is a three- or four-digit security code that is printed on the back of credit cards in the card\'s signature panel (or on the front for American Express cards).'), '<br>', '<br>'));
        $code->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/');
        /**/
        $fieldSet = $form->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)'));
        $street = $fieldSet->addText('cc_street')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address'));
        $city = $fieldSet->addText('cc_city')->setLabel(___('City'))->addRule('required', ___('Please enter City'));
        $zip = $fieldSet->addText('cc_zip')->setLabel(___('ZIP'))->addRule('required', ___('Please enter ZIP code'));
        $country = $fieldSet->addSelect('cc_country')->setLabel(___('Country'))->setId('f_cc_country')->loadOptions(Am_Di::getInstance()->countryTable->getOptions(true));
        $country->addRule('required', ___('Please enter Country'));
        $group = $fieldSet->addGroup()->setLabel(___('State'));
        $group->addRule('required', ___('Please enter State'));
        $stateSelect = $group->addSelect('cc_state')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true));
        $stateText = $group->addText('cc_state')->setId('t_cc_state');
        $disableObj = $stateOptions ? $stateText : $stateSelect;
        $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none');
        /**/
        $form->addSubmit('', array('value' => $label));
        $form->addHidden('id')->setValue($this->_request->get('id'));
        $form->addHidden('paymill_token', 'id=paymill_token')->addRule('required');
        //$key = json_encode($this->plugin->getConfig('public_key'));
        $key = $this->plugin->getConfig('public_key');
        $amount = $this->invoice->isFirstPayment() ? $this->invoice->first_total : $this->invoice->second_total;
        $amount = sprintf('%.02f', $amount) * 100;
        $form->addProlog('<script type="text/javascript" src="https://bridge.paymill.com/"></script>');
        $form->addScript()->setScript("var PAYMILL_PUBLIC_KEY = '" . $key . "';");
        if ($this->testMode) {
            $form->addScript()->setScript("var PAYMILL_TEST_MODE = true;");
        }
        $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js'));
        $form->addScript()->setScript(<<<CUT
jQuery(function(\$){
    \$("form#cc-paymill").submit(function(event){
        var frm = \$(this);
        \$('.submit-button').attr("disabled", "disabled");
                
        if (frm.find("input[name=paymill_token]").val() > '')
            return true; // submit the form!
        event.stopPropagation();

        paymill.createToken({
            number:         frm.find("#cc_number").val(),       // required
            exp_month:      frm.find("[name='cc_expire[m]']").val(), // required
            exp_year:       frm.find("[name='cc_expire[y]']").val(),  // required
            cvc:            frm.find("#cc_code").val(),          // required
            amount_int:     {$amount},   // required, z.B. "4900" for 49.00 EUR
            currency:       '{$this->invoice->currency}',          // required
            cardholder:     frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val()    // optional
        }, function(error, result){ // handle response
            if (error) {
                frm.find("input[type=submit]").prop('disabled', null);
                var el = frm.find("#cc_number");
                var cnt = el.closest(".element");
                cnt.addClass("error");
                cnt.find("span.error").remove();
                
                var errorMessage = '';
                switch (error.apierror)
                {
                    case 'internal_server_error':
                        errorMessage = 'Communication with PSP failed';
                        break;
                    case 'invalid_public_key':
                        errorMessage = 'Invalid Public Key';
                        break;
                    case 'unknown_error':
                        errorMessage = 'Unknown Error';
                        break;

                    case '3ds_cancelled':
                        errorMessage = 'Password Entry of 3-D Secure password was cancelled by the user';
                        break;
                    case 'field_invalid_card_number':
                        errorMessage = 'Missing or invalid creditcard number';
                        break;
                    case 'field_invalid_card_exp_year':
                        errorMessage = 'Missing or invalid expiry year';
                        break;
                    case 'field_invalid_card_exp_month':
                        errorMessage = 'Missing or invalid expiry month';
                        break;
                    case 'field_invalid_card_exp':
                        errorMessage = 'Card is no longer valid or has expired';
                        break;
                    case 'field_invalid_card_cvc':
                        errorMessage = 'Invalid checking number';
                        break;
                    case 'field_invalid_card_holder':
                        errorMessage = 'Invalid cardholder';
                        break;
                    case 'field_invalid_amount_int':
                        errorMessage = 'Invalid or missing amount for 3-D Secure';
                        break;
                    case 'field_invalid_amount':
                        errorMessage = 'Invalid or missing amount for 3-D Secure deprecated, see blog post';
                        break;
                    case 'field_invalid_currency':
                        errorMessage = 'Invalid or missing currency code for 3-D Secure';
                        break;
                    case 'field_invalid_account_number':
                        errorMessage = 'Missing or invalid bank account number';
                        break;
                    case 'field_invalid_account_holder':
                        errorMessage = 'Missing or invalid bank account holder';
                        break;
                    case 'field_invalid_bank_code':
                        errorMessage = 'Missing or invalid bank code ';
                        break;
                    default:
                        errorMessage = error.apierror;
                }
                el.after("<span class='error'><br />"+errorMessage+"</span>");
            } else {
                frm.find("input[name=paymill_token]").val(result.token);
                frm.submit();
            }
        });                
        frm.find("input[type=submit]").prop('disabled', 'disabled');
        return false;
    });
});   
CUT
);
        return $form;
    }
예제 #3
0
파일: stripe.php 프로젝트: grlf/eyedock
    public function createForm($label, $cc_mask = null)
    {
        $form = new Am_Form('cc-stripe');
        $name = $form->addGroup()->setLabel(___("Cardholder Name\n" . 'cardholder first and last name, exactly as on the card'));
        $name->addRule('required', ___('Please enter credit card holder name'));
        $name_f = $name->addText('cc_name_f', array('size' => 15, 'id' => 'cc_name_f'));
        $name_f->addRule('required', ___('Please enter credit card holder first name'))->addRule('regex', ___('Please enter credit card holder first name'), '|^[a-zA-Z_\' -]+$|');
        $name_l = $name->addText('cc_name_l', array('size' => 15, 'id' => 'cc_name_l'));
        $name_l->addRule('required', ___('Please enter credit card holder last name'))->addRule('regex', ___('Please enter credit card holder last name'), '|^[a-zA-Z_\' -]+$|');
        $cc = $form->addText('', array('autocomplete' => 'off', 'size' => 22, 'maxlength' => 22, 'id' => 'cc_number'))->setLabel(___('Credit Card Number'), ___('for example: 1111-2222-3333-4444'));
        if ($cc_mask) {
            $cc->setAttribute('placeholder', $cc_mask);
        }
        $cc->addRule('required', ___('Please enter Credit Card Number'))->addRule('regex', ___('Invalid Credit Card Number'), '/^[0-9 -]+$/');
        class_exists('Am_Form_CreditCard', true);
        // preload element
        $expire = $form->addElement(new Am_Form_Element_CreditCardExpire('cc_expire'))->setLabel(___("Card Expire\n" . 'Select card expiration date - month and year'));
        $expire->addRule('required', ___('Please enter Credit Card expiration date'));
        $code = $form->addPassword('', array('autocomplete' => 'off', 'size' => 4, 'maxlength' => 4, 'id' => 'cc_code'))->setLabel(___('Credit Card Code'), sprintf(___('The "Card Code" is a three- or four-digit security code that is printed on the back of credit cards in the card\'s signature panel (or on the front for American Express cards).'), '<br>', '<br>'));
        $code->addRule('required', ___('Please enter Credit Card Code'))->addRule('regex', ___('Please enter Credit Card Code'), '/^\\s*\\d{3,4}\\s*$/');
        $fieldSet = $form->addFieldset(___('Address Info'))->setLabel(___("Address Info\n" . '(must match your credit card statement delivery address)'));
        $street = $fieldSet->addText('cc_street')->setLabel(___('Street Address'))->addRule('required', ___('Please enter Street Address'));
        $city = $fieldSet->addText('cc_city')->setLabel(___('City '))->addRule('required', ___('Please enter City'));
        $zip = $fieldSet->addText('cc_zip')->setLabel(___('ZIP'))->addRule('required', ___('Please enter ZIP code'));
        $country = $fieldSet->addSelect('cc_country')->setLabel(___('Country'))->setId('f_cc_country')->loadOptions(Am_Di::getInstance()->countryTable->getOptions(true));
        $country->addRule('required', ___('Please enter Country'));
        $group = $fieldSet->addGroup()->setLabel(___('State'));
        $group->addRule('required', ___('Please enter State'));
        /** @todo load correct states */
        $stateSelect = $group->addSelect('cc_state')->setId('f_cc_state')->loadOptions($stateOptions = Am_Di::getInstance()->stateTable->getOptions(@$_REQUEST['cc_country'], true));
        $stateText = $group->addText('cc_state')->setId('t_cc_state');
        $disableObj = $stateOptions ? $stateText : $stateSelect;
        $disableObj->setAttribute('disabled', 'disabled')->setAttribute('style', 'display: none');
        $form->addSubmit('', array('value' => $label));
        $form->addHidden('id')->setValue($this->_request->get('id'));
        $form->addHidden('stripe_info', 'id=stripe_info')->addRule('required');
        $key = json_encode($this->plugin->getConfig('public_key'));
        $form->addScript()->setScript(file_get_contents(dirname(__FILE__) . '/../../default/views/public/js/json2.min.js'));
        $form->addScript()->setScript(<<<CUT
jQuery(function(\$){
    function am_make_base_auth(user, password) {
        return "Basic " + btoa(user + ':' + password);
    }
    \$("form#cc-stripe").submit(function(event){
        var frm = \$(this);
        if (frm.find("input[name=stripe_info]").val() > '')
            return true; // submit the form!
        event.stopPropagation();
        Stripe.setPublishableKey({$key});
        Stripe.createToken({
            number: frm.find("#cc_number").val(),
            cvc: frm.find("#cc_code").val(),
            exp_month: frm.find("[name='cc_expire[m]']").val(),
            exp_year: frm.find("[name='cc_expire[y]']").val(),
            name: frm.find("#cc_name_f").val() + " " + frm.find("#cc_name_l").val(),
            address_zip : frm.find("[name=cc_zip]").val(),
            address_line1 : frm.find("[name=cc_street]").val(),
            address_country : frm.find("[name=cc_country]").val(),
            address_city : frm.find("[name=cc_city]").val(),
            address_state : frm.find("[name=cc_state]").val()
            
        }, function(status, response){ // handle response
            if (status == '200')
            {
                frm.find("input[name=stripe_info]").val(JSON.stringify(response));
                frm.submit();
            } else {
                frm.find("input[type=submit]").prop('disabled', null);
                var msg;
                if (response.error.type == 'card_error')
                    msg = response.error.message;
                else
                    msg = 'Payment failure, please try again later';
                var el = frm.find("#cc_number");
                var cnt = el.closest(".element");
                cnt.addClass("error");
                cnt.find("span.error").remove();
                el.after("<span class='error'><br />"+msg+"</span>");
            }
        });
        frm.find("input[type=submit]").prop('disabled', 'disabled');
        return false;
    });
});   
CUT
);
        $form->setDataSources(array($this->_request, new HTML_QuickForm2_DataSource_Array($this->getDefaultValues($this->invoice->getUser()))));
        return $form;
    }
예제 #4
0
    public function initConfigForm(Am_Form $form)
    {
        $id = $this->field->name . '-display-type';
        $id_value = $this->field->name . '-value';
        $form->addSelect('display_type')->setLabel(___('Display Type'))->setId($id)->loadOptions(array(self::TYPE_NORMAL => ___('Normal'), self::TYPE_READONLY => ___('Read-only'), self::TYPE_HIDDEN => ___('Hidden')));
        $form->addText('value')->setId($id_value)->setLabel(___("Default Value for this field\n" . 'hidden field will be populated with this value'));
        $type_hidden = self::TYPE_HIDDEN;
        $form->addScript()->setScript(<<<CUT
\$(function(){
    \$('#{$id}').change(function(){
        \$('#{$id_value}').closest('.row').toggle(\$(this).val() == '{$type_hidden}');
    }).change()
});
CUT
);
        $form->addAdvCheckbox('skip_access_check')->setLabel(___("Do not check Access Permissions\nfor this field on this form (show it without any conditions)"));
    }
예제 #5
0
 protected function createForm()
 {
     $form = new Am_Form();
     $form->addCsrf();
     $form->addText('login', array('disabled' => 'disabled'))->setLabel(___('Username'));
     $pass0 = $form->addPassword('pass0')->setLabel(___('New Password'));
     $pass0->addRule('minlength', ___('The password should be at least %d characters long', $this->getDi()->config->get('pass_min_length', 4)), $this->getDi()->config->get('pass_min_length', 4));
     $pass0->addRule('maxlength', ___('Your password is too long'), $this->getDi()->config->get('pass_max_length', 32));
     $pass0->addRule('required', 'This field is required');
     if ($this->getDi()->config->get('require_strong_password')) {
         $pass0->addRule('regex', ___('Password should contain at least 2 capital letters, 2 or more numbers and 2 or more special chars'), $this->getDi()->userTable->getStrongPasswordRegex());
     }
     $pass1 = $form->addPassword('pass1')->setLabel(___('Confirm Password'));
     $pass1->addRule('eq', ___('Passwords do not match'), $pass0);
     $form->addHidden(self::SECURITY_VAR);
     $form->addSaveButton(___('Change Password'));
     return $form;
 }