Friday, May 29, 2015

How to get Latitude & Longitude using zipcode in php?

Get Latitude & Longitude:

It is a very simple way to get latitude & longitude using zipcode in php.
For this you have to use google api's.
Here is a function for doing this:
public function getLatLng($zip)
    {
        $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=$zip&sensor=true";
        $xml = simplexml_load_file($request_url) or die("url not loading");
        $status = $xml->status;
        $lat = $lng = 0;
        if ($status == "OK") {
            $lat = $xml->result->geometry->location->lat;
            $lng = $xml->result->geometry->location->lng;
        }
        $loc = array('lat' => $lat, 'lng' => $lng);
        return $loc;
    }
Here $zip is a zipcode variable. It will return a array consisting of latitude & longitude.
Thanks.

Friday, May 22, 2015

Easy & secure way to do digital signature on any online document in php

Easy way for Digital Signature:

For easily digital signature on any online document you have to do some following steps:

1. Create an account on Hellosign.com . Due to this you'll get an API Key.

2. After creating an account create a test app from here. . Due to this you'll get a client id.

Now using this install its package in your project.

Now write this code in your php file.

        require_once 'vendor/autoload.php';
        $client = new HelloSign\Client('YOUR_API_KEY');
        $request = new HelloSign\SignatureRequest;
        $request->enableTestMode();
        $request->setSubject('SUBJECT_NAME');
        $request->setMessage('SUBJECT_MESSAGE');
        $request->addSigner('YOUR_EMAIL', 'Me');
        $request->addFile('PATH_OF_FILE');

        $client_id = 'YOUR_CLIENT_ID';
        $embedded_request = new HelloSign\EmbeddedSignatureRequest($request, $client_id);
        $response = $client->createEmbeddedSignatureRequest($embedded_request);
        $signature = $response->signatures[0]->signature_id;
        $response = $client->getEmbeddedSignUrl($signature);
 

<script type="text/javascript" src="//s3.amazonaws.com/cdn.hellofax.com/js/embedded.js"></script>
<script type="text/javascript">
    window.onload = function() {
    HelloSign.init("YOUR_CLIENT_ID");
    HelloSign.open({
        url: "<?php echo $response->sign_url; ?>",
        allowCancel: true,
        messageListener: function (eventData) {
            alert("HelloSign event received");
        }
    });
    }
</script>

Run this file and see the magic.

Thanks


Friday, May 15, 2015

How to access any behavior function in humhub (Developed in Yii Framework) ?

Access behavior function in humhub:

For access any behavior function we have to create a behavior function on our file in which we direct set its class.

By adding the SpaceControllerBehavior you are able to access current space in your controllers.
Make sure you always pass the current space guid (sguid) in your urls.

When using the method createContainerUrl (provided by SpaceControllerBehavior or UserControllerBehavior) the
current space or user guid is automatically added to urls.

    public function behaviors()
    {
        return array(
            'SpaceControllerBehavior' => array(
                'class' => 'application.modules_core.space.behaviors.SpaceControllerBehavior',
            ),
        );
    }

    public function actionTest() {
        $currentSpace = $this->getSpace();
       
        $this->redirect($this->createContainerUrl('test2'));
       
    }

    public function actionTest2() {
        $currentSpace = $this->getSpace();
    }


Thanks

Friday, May 8, 2015

Easy & Secure client side form validation using jquery validation plugin.

Jquery Validation Plugin:

This is very easy and secure method for client side form validation using validation plugin.

For this you have to include these three jquery validation libraries.

1. First
2. Second
3. Third

After this in your <script> you will add this:


<script>
    $(document).ready(function () {
        $('#myForm').validate({
            ignore: [],
            rules: {
                filename: {
                    required: true,
                    extension: 'docx|doc|gif|jpg|jpeg|png|pdf'                }
              },
            submitHandler: function(form) {
                $('#myForm')[0].submit();
                return false;
            }
        });
    });
</script>

<form method="post" action="/create2" id="myForm" enctype="multipart/form-data">
 <input type="file" name="filename" class="form-control"/>
 <label for="filename" class="error" style="display:none;color:red">This field is required</label> 
 <input type="submit" class="btn btn-primary" id="submit" name="submit" value="submit">
</form>

This will validate your file as required & its extension format.
 Also, you can add filesize in it according to your need.

Thanks