getBootstrap: javascript in modal dialogue

I made an administration console using getBootstrap framework. Wonderful and simple in use mechanism to create fully functional sites.
At some moment, I faced a problem, that I need more “stay in one page” solution. For that purposes, I started looking deeper to utilizing modal dialogues.

My first experience was with adding pictures to products in our database.
kosher_admin_imageslist It is a very simple example how you can use modal dialogues for your own forms. The list of images is taken from Microsoft Azure image search API. User selects proper image from the list and saves. After saving image in proper row is set to selected and product is updated in database.
The code is the following:



Modal container is needed to put content of our script into.

Now a little sneak view of our images_list.php

$request = $_GET["request"];

$rootUri = '';
$serviceOp = "Image";

        $requestUri = "$rootUri/$serviceOp?\$format=json&Query='".urlencode($request)."'";
        // Encode the credentials and create the stream context.

        $data = array(
            'http' => array(
            'request_fulluri' => true,

        // ignore_errors can help debug – remove for production. This option added in PHP 5.2.10
            'ignore_errors' => false,
            'header' => "Authorization: Basic $auth")

        $context = stream_context_create($data);

        // Get the response from Bing.
        $response = file_get_contents($requestUri, 0, $context);
        $jsonObj = json_decode($response);

        $image_url = "";
        $resultStr ="";
        foreach($jsonObj->d->results as $value) {
            $checked = "";
            if ($i==1)
                $checked = "checked";
            switch ($value->__metadata->type) {
                case 'WebResult':
                    $resultStr .= "Url}\">{$value->Title}


"; break; case 'ImageResult': $resultStr .= "
  • " . "
  • "; $image_url = $value->MediaUrl; break; } } ?>

    And a little bit of JavaScript to submit our form and do all the needed actions:

    $(document).on('submit','form#modal-form', function(event) {
            var id = $("input#id").val();
                        type: 'POST',
                        url: $(this).attr('action'),
                        data: $(this).serialize(), //your form datas to post
                        success: function(response)
                        error: function()
            return false;

    Another big task was to make edit dialogue with automatically uploading image.
    kosher_admin_edit I used an interesting project to make file upload fast and reliable jQuery File Upload. This project gives you possibility to upload files just after you selected a file on your computer hard drive. The problem I met was, that there is no simple way to assign fileUpload to the element in modal dialogue. So, I found the following solution for this:

    $('#myModal').on('', function(e) {
            $('.modal-body #fileuploadModal').fileupload({
                dataType: 'json',
                done: function (e, data) {
                    $.each(data.result.files, function (index, file) {
                        $('#fileupload-imageModal').attr("src", file.url);
                progressall: function (e, data) {
                        var progress = parseInt(data.loaded / * 100, 10);
                        $('#progressModal .bar').css(
                            progress + '%'

    This issue was the most difficult to solve. I spent several hour to find the solution. Actually, event ‘’ is the key to success 😉

    Leave a Reply

    %d bloggers like this: