1

I have a GWT app with inputs (let's say Name, Address, Email). After user input all the required fields and press submit button, a PHP page will display the inputs from the GWT app. How can I connect my GWT app to php? I'm using Request Builder now. Do I still have to use XML to pass the GWT inputs to PHP? Please help. I'm just starting to learn GWT here.

Thanks in advance.

1 Answer 1

1

You actually don't need RequestBuilder for something like that.
It would be sufficient if you redirect to the PHP url and append your inputs as GET parameters. So for example in the click handler you can do something like that:

submitButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        String linkURL = "somePage.php?name="+name+"&address="+address+"&email="+email;
         Window.Location.assign(linkURL);
    }
});

and then in the PHP page you can retrieve the parameters in this way:

$name = $_GET['name'];
$address = $_GET['address'];
$email = $_GET['email'];

Update

If you want to use RequetBuilder you have to do something like that:

submitButton.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        RequestBuilder request = new RequestBuilder(POST,PHP_URL);
        JSONObject jsonValue = new JSONObject();
        jsonValue.put("name", new JSONString(name));
        jsonValue.put("address", new JSONString(address));
        jsonValue.put("email", new JSONString(email));
        request.setHeader("Content-Type", "application/json");
        request.sendRequest(jsonValue.toString(),new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                     //retrieve a uniqueid or so and redirect to the PHP page which displays the infos
                } else {
                   // displayError("Couldn't retrieve 

                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                 //displayError("Couldn't retrieve JSON");
            }
         });

    }
});

On the server you just access the global $_POST variable to get the values:

$name = @_POST['name']
Sign up to request clarification or add additional context in comments.

9 Comments

hello. Thank you for answering this question. Actually, I've already done this but I was thinking what if I have to pass data like passwords? This one's not safe. Can I use XML/JSON to pass this instead? I still don't know a thing about JSON but I've read that it can be used to pass GWT to PHP. I just don't know how to exactly do it :(
Passwords is another issue. However I don' think you will be much safer with RequestBuilder anyways because RequestBuilder is also "only" creating a HTTP request as if you would do it via the normal browser URL. With RequestBuilder you can use POST instead (still they can be read out). See my update for details
hi timeu. what code will i put on my server side? sorry if i don't know a thing here.. :(
see my update. RequestBuilder basically just creates a HTTP request. It's the same as if you would directly call the php page.
it doesn't work in my code. i've tried this one. actually, my php code is something like this: foreach( $_POST as $key=>$value ) { echo "$key : $value<br />"; }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.