question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newbie issue - $_REQUEST don't populate

See original GitHub issue

First of all, really thanks for W2UI! It’s amazing!

I am a newbie to w2ui and I have serios problems with something really basic.

I am trying to get data from my server (LAMP) but I get always the same (Command “” is not recognized). I did everything that I know. I try for more then 15 hours and nothing.

image

I get data only when I assembly a array in PHP and encode to Json to pass with an ECO. But I want to make it work with the default method to send request.

I tried to use the example that is in the folder " /server/php " and get the same issue. I try all examples that have server connection.

My $_REQUEST array do not receive data, if I send an var in the url. …php?param=1 I get it into the users.php. But I do not receive $_REQUEST[‘cmd’] and the other vars.

Please some one help me. Thanks in advance.

My code: users.php I did customization in server, user, pass… `<?php

require(“w2db.php”); require(“w2lib.php”);

$db = new dbConnection(“mysql”); $db->connect(“localhost”, “xxx”, “xxx”, “tdr_DB”, “3306”);

switch ($_REQUEST[‘cmd’]) {

case 'get':
    if (array_key_exists('recid', $_REQUEST)){  // if true , then is a 'get-record' only one record with recid
        $sql = "SELECT userid, fname, lname, email, login, password
                FROM users
                WHERE userid = ".$_REQUEST['recid'];
        $res = $w2grid->getRecord($sql);
    }
    else{        
        $sql  = "SELECT * FROM users       
                 WHERE ~search~ ORDER BY ~sort~";
        $res = $w2grid->getRecords($sql, null, $_REQUEST);
    }  
     $w2grid->outputJSON($res);
    break;

case 'delete':
    $res = $w2grid->deleteRecords("users", "userid", $_REQUEST);
    $w2grid->outputJSON($res);
    break;

//case 'get-record':
//    break;

case 'save':
    $res = $w2grid->saveRecord('users', 'userid', $_REQUEST);
    $w2grid->outputJSON($res);
    break;

default:
    $res = Array();
    $res['status']  = 'error';
    $res['message'] = 'Command "'.$_REQUEST['cmd'].'" is not recognized.';
    $res['postData']= $_REQUEST;
    $w2grid->outputJSON($res);
    break;

} `

in index.php is: `<!DOCTYPE html>

<html> <head> <link rel="stylesheet" type="text/css" href="../../dist/w2ui.min.css" /> <script type="text/javascript" src="../../libs/jquery/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="../../dist/w2ui.min.js"></script> </head> <body> <div id="users" style="width: 100%; height: 600px;"></div> </body> <script> $(function () { // define and render grid $('#users').w2grid({ name : 'users', url : 'users.php', header : 'List of Users', show: { header : true, toolbar : true, footer : true, toolbarAdd : true, toolbarDelete : true }, columns: [ { field: 'fname', caption: 'First Name', size: '150px', searchable: true }, { field: 'lname', caption: 'Last Name', size: '150px', searchable: true }, { field: 'email', caption: 'Email', size: '100%', searchable: true }, { field: 'login', caption: 'Login', size: '150px', searchable: true } ], onAdd: function (event) { editUser(0); }, onDblClick: function (event) { editUser(event.recid); } });
// defined form https://api.myjson.com/bins/6ayrt
$().w2form({
    name     : 'user_edit',
    url     : 'users.php',
    style     : 'border: 0px; background-color: transparent;',
    formHTML:
        '<div class="w2ui-page page-0">'+
        '    <div class="w2ui-label">First Name:</div>'+
        '    <div class="w2ui-field">'+
        '        <input name="fname" type="text" size="35"/>'+
        '    </div>'+
        '    <div class="w2ui-label">Last Name:</div>'+
        '    <div class="w2ui-field">'+
        '        <input name="lname" type="text" size="35"/>'+
        '    </div>'+
        '    <div class="w2ui-label">Email:</div>'+
        '    <div class="w2ui-field">'+
        '        <input name="email" type="text" size="35"/>'+
        '    </div>'+
        '    <div class="w2ui-label">Login:</div>'+
        '    <div class="w2ui-field">'+
        '        <input name="login" type="text" size="25"/>'+
        '    </div>'+
        '    <div class="w2ui-label">Password:</div>'+
        '    <div class="w2ui-field">'+
        '        <input name="password" type="password" size="25"/>'+
        '    </div>'+
        '</div>'+
        '<div class="w2ui-buttons">'+
        '    <input type="button" value="Cancel" name="cancel">'+
        '    <input type="button" value="Save" name="save">'+
        '</div>',
    fields: [
        { name: 'fname', type: 'text', required: true },
        { name: 'lname', type: 'text', required: true },
        { name: 'email', type: 'email' },
        { name: 'login', type: 'text', required: true },
        { name: 'password', type: 'text', required: false },
    ],
    actions: {
        "save": function () {
            this.save(function (data) {
                if (data.status == 'success') {
                    w2ui['users'].reload();
                    $().w2popup('close');
                }
                // if error, it is already displayed by w2form
            });
        },
        "cancel": function () {
            $().w2popup('close');
        },
    }
});

});

function editUser(recid) { $().w2popup(‘open’, { title : (recid == 0 ? ‘Add User’ : ‘Edit User’), body : ‘<div id="user_edit" style="width: 100%; height: 100%"></div>’, style : ‘padding: 15px 0px 0px 0px’, width : 500, height : 300, onOpen : function (event) { event.onComplete = function () { w2ui[‘user_edit’].clear(); w2ui[‘user_edit’].recid = recid; $(‘#w2ui-popup #user_edit’).w2render(‘user_edit’); } } }); } </script>

</html>`

I created the table in mysql. I am able to get data with my functions… image

Sorry this basic question, but I did everything that I know.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
mpf82commented, Jun 17, 2020

@AlexKovynev If you’re using the latest master then “get” will no longer be sent to the server for a “get” request and in addition “cmd” has been renamed to “action” for “delete”/“save” commands.

That means, if the data does not contain an “action” attribute, you should handle it as “get”.

If you’re using 1.5 RC1 then see my answer above.

You could always inspect your browser’s network tab in the dev console to see what exactly gets sent to your server, or just inspect all the data that your server receives.

0reactions
AlexVDemcommented, Jun 17, 2020

@AlexKovynev If you’re using the latest master then “get” will no longer be sent to the server for a “get” request and in addition “cmd” has been renamed to “action” for “delete”/“save” commands.

That means, if the data does not contain an “action” attribute, you should handle it as “get”.

If you’re using 1.5 RC1 then see my answer above.

You could always inspect your browser’s network tab in the dev console to see what exactly gets sent to your server, or just inspect all the data that your server receives.

Thanks for reply. I noticed, than new version make a new problems. 😃 I’ve set w2utils.settings.dataType = ‘JSON’; and url: { get: ‘users.php’, save: ‘users.php’, remove: ‘users.php’ }, and now I get correct JSON string to my users.php (like {“cmd”:“get”,“selected”:[],“limit”:5,“offset”:0}). But I have another issue: users.php (in fact - getRecords() from w2lib.php) returns strange data array looks like: ERROR: Server communication failed. EXPECTED: {status: “success”, total: 5, records: Array(1)} OR: {status: “error”, message: “error message”} RECEIVED: —Array —Array ( [0] => Array ( [0] => 18 )

) —Array ( [0] => Array ( [0] => 1 [1] => Name1 [2] => LastName1 [3] => name1@mail.net [4] => Name1 [5] => 1234567 )

[1] => Array
    (
        [0] => 2
        [1] => Name2
        [2] => LastName2
        [3] => name2@mail.net
        [4] => Name2
        [5] => 11223
    )

[2] => Array
    (
        [0] => 3
        [1] => Name3
        [2] => LastName3
        [3] => name3@mail.net
        [4] => Name3
        [5] => 11223
    )

) As result I got error 500 (Internal Server Error) and “AJAX error. See console for more details.” Seems to me, I always receive wrong array and json_encode($data) can’t encode it in JSON string for w2grid(). Buy the way, I can use “add record” button, and add records to MySQL and it works almost correct (do not close popup window after Save). Do you have any idea, what’s wrong with getrecords()? I will appreciate for help. Thanks. PS My code in attached file.

w2grid.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hello World - GitHub Docs
This tutorial teaches you GitHub essentials like repositories, branches, commits, and pull requests. You'll create your own Hello World repository and learn ...
Read more >
A beginner's guide to Mastodon, the open source Twitter ...
How do you create a Mastodon account? ... When you arrive on the Mastodon website, you can click a button called “create account,”...
Read more >
Tutorial: Create and run your first GitLab CI/CD pipeline
Create an issue if there's something you don't like about this feature. Propose functionality by submitting a feature request.
Read more >
How to debug for absolute beginners - Visual Studio
We expect that you already ran into a problem in your code, otherwise you ... Next, we'll create an application that has a...
Read more >
How to Fix Common SSL Issues in WordPress (Beginner's ...
WordPress will not automatically redirect HTTP requests to HTTPS unless you tell it to do so. If you are using a plugin like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found