Git Product home page Git Product logo

yii2-address-form's Introduction

Yii2 Address-form module

Scrutinizer Code Quality Build Status Code Coverage

A module doing address-form fields with dependent pre-set country-region drop-downs. Countries & regions powered by:

powered by rinvex/countries

250 countries & regions worldwide available

Example

add module config

the module part will take care of dep-drop ajax queries


    'modules' => [
        //...
        'addressform' =>[
            'class' => \tonisormisson\addressform\Module::class,
        ],
        //...
    ]

place the widet

use tonisormisson\addressform\AddressForm; 

echo AddressForm::widget([
    'allowedCountries' => ["EE", "LV", "LT"],
    'defaultCountry' => "EE",
    'placeHolders' = [
        // custom placeholders here if needed
        'country' => ,
        'state' => ,
        'city' => ,
        'postCode' => ,
        'addressLine1' => ,
        'addressLine2' => ,
    ],
            
]);

and catch the address in controller

use tonisormisson\addressform\models\Address;
$address = new Address();
$address->load(Yii::$app->request->post());

// load the address to your models
// eg :
$model->address_data = Json::encode($address);

yii2-address-form's People

Contributors

tonisormisson avatar

Stargazers

Mort avatar Michael Laweh avatar Uldis Nelsons avatar

Watchers

 avatar

Forkers

raimon-segura

yii2-address-form's Issues

Overriding Placeholders not working

In setting the placeHolders I expect it to show my set values but it rather shows the default set in public function init()

 <?php    
                echo AddressForm::widget([
                        'form' => $form,
                        'disabledFields' => ['name'],
                        //'allowedCountries' => ["EE", "LV", "LT"],
                        'defaultCountry' => "GH",
                        'placeHolders' => [
                            // custom placeholders here if needed
                            'country' => '',
                            'state' => '',
                            'city' => 'Enter your city',
                            'postCode' => 'Enter your postcode',
                            'addressLine1' => 'Your Street Address',
                            'addressLine2' => '',
                        ],
                                
                    ]); 
                ?>

SETTING THE DEFAULT COUNTRY

Is there a way to set the default value for the country?

example

<?php    
                echo AddressForm::widget([
                        'form' => $form,
                        'disabledFields' => ['name'],
                        'allowedCountries' => ["EE", "LV", "LT"],
                        'defaultCountry' => 'GH',
                        'placeHolders' => [
                            // custom placeholders here if needed
                            'country' => '',
                            'state' => '',
                            'city' => '',
                            'postCode' => '',
                            'addressLine1' => '',
                            'addressLine2' => '',
                        ],
                                
                    ]); 
                ?>

so this way the country is selected automatically and user can choose to change as usual. I tried with the 'country' => 'GH' under placeHolders but didn't work.

Unable to verify your data submission

I get the error whenever the form tries to load the cities.

investigating the error

POST http://example.com/addressform/query/regions

form data

depdrop_parents[0] : "GH"
depdrop_all_params[address-country]: "GH"

Request Payload:

depdrop_parents%5B0%5D=GH&depdrop_all_params%5Baddress-country%5D=GH

Response:


{
    "name": "Bad Request",
    "message": "Unable to verify your data submission.",
    "code": 0,
    "status": 400,
    "type": "yii\\web\\BadRequestHttpException"
}

what could cause the error?

using "yiisoft/yii2": "2.0.38",

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.