Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Post data to php form
Forum Updated to NodeBB v4.3 + New Features

Post data to php form

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 14.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca72
    wrote on 4 Apr 2011, 15:38 last edited by
    #1

    Hello i can use something of webkit to post data to a php form?
    ex:
    @ <table>
    <b>Inserisci la password</b>
    <form method="POST">
    <input type="passwd" name="password"></input>;
    <input type="submit" name="Entra" value="entra"></input>;
    </form>
    </table>

    </div>@
    how i can pass the value "password"?

    Thanks
    Luca

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on 4 Apr 2011, 16:00 last edited by
      #2

      Hi,

      You should specify destination URL (aka the php script location) as an attribute called action.

      @<form method="POST" action="http://example.com">@

      Best regards,
      Leon

      http://anavi.org/

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on 4 Apr 2011, 16:07 last edited by
        #3

        Since you mentioned Webkit, the most straightforward way IMHO is to use a little piece of JavaScript that fills in and submits the form.

        If you're interested in submitting a form without using Webkit, then you can use QNetworkAccessManager::get/post (depending on the form's method). For the former, you can build up the right URL by using QUrl and addQueryItem. For the latter, there's nothing in Qt 4.7 if you want to submit multipart/form-data (but the QHttpMultiPart/QHttpPart classes will be introduced in Qt 4.8), while instead you may use QUrl again if you want to submit the form as application/x-www-form-urlencoded.

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca72
          wrote on 4 Apr 2011, 16:12 last edited by
          #4

          The url is thwe same,
          the php post don't send data via url, this is my problem

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on 4 Apr 2011, 16:49 last edited by
            #5

            This snippet is untested and adapted from "this post":http://stackoverflow.com/questions/2214595/how-can-i-create-a-http-post-request-with-qt-4-6-1, it should work or give you at least a hint on how to proceed:

            @
            QUrl params;
            params.params.addEncodedQueryItem("password", QUrl::toPercentEncoding("yourvalue"));
            // the string contains a ? at the beginning
            // mid(1) strips this off
            QByteArray paramBytes = params.toString().mid(1);

            QNetworkRequest request(QUrl("http://your.server.com/path/to/send"));
            request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");

            QNetworkAccessManager *nam = new QNetworkAccessManager;
            QNetworkReply *reply = nam(request, paramBytes);
            @

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vcsala
              wrote on 4 Apr 2011, 16:54 last edited by
              #6

              [quote author="peppe" date="1301933226"]If you're interested in submitting a form without using Webkit, then you can use QNetworkAccessManager::get/post (depending on the form's method). For the former, you can build up the right URL by using QUrl and addQueryItem. For the latter, there's nothing in Qt 4.7 if you want to submit multipart/form-data (but the QHttpMultiPart/QHttpPart classes will be introduced in Qt 4.8), while instead you may use QUrl again if you want to submit the form as application/x-www-form-urlencoded.[/quote]

              Just reflecting if it is possible to send form-data or not with QNetworkAccessManager: it is possible, you have to put together your name/value pairs to a string and send it through as the content of your post request. You can see it below:

              @void ClientLogin::doLogin(const QString email, const QString password, const QByteArray captchaToken, const QString captchaValue)
              {
              QUrl url = QUrl(CLIENTLOGIN_URL);
              QNetworkRequest request;
              QByteArray content = "";

              request.setUrl(url);
              
              content += "accountType=HOSTED_OR_GOOGLE&";
              content += "Email=" +  email.toAscii() + "&";
              content += "Passwd=" + password.toAscii() + "&";
              content += "service=jotspot&";
              content += "source=gsites-0.1a";
              
              if (!captchaToken.isEmpty()) {
                  content += "&";
                  content += "logintoken=" + captchaToken + "&";
                  content += "logincaptcha=" + captchaValue.toAscii();
              }
              
              m_manager.post(request, content);
              

              }
              @

              ADDED: actually this snippet is part from my working app, so it is tested

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dangelog
                wrote on 4 Apr 2011, 18:11 last edited by
                #7

                The snippet is slightly wrong --- you're supposed to:

                • percent-encode the fields (QByteArray::toPercentEncoding), otherwise a field containing spaces or ampersands will blow up everything;
                • don't use the "dangerous" toAscii() but toUtf8() (see also http://tools.ietf.org/html/rfc3986#section-2.5 );
                • set the content-type for the post to "application/x-www-form-urlencoded; charset=utf-8" (or whatever encoding you are using).

                Software Engineer
                KDAB (UK) Ltd., a KDAB Group company

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vcsala
                  wrote on 4 Apr 2011, 18:34 last edited by
                  #8

                  @peppe: of course you are right, it is still work in progress and moreover it is only a small application for learning purposes (therefore it will never be thorougly tested). My aim was just to show that you can send form data with using QNetworkAccessManager.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dangelog
                    wrote on 4 Apr 2011, 20:09 last edited by
                    #9

                    You're absolutely right -- perhaps I expressed myself badly before.

                    You CAN do it as of now using QNetworkAccessManager. The only culprit is that in 4.7 there's nothing to help you for making multipart/form-data POST requests. application/x-www-form-urlencoded POST requests are easy to deal with (by hand or using QUrl).

                    Software Engineer
                    KDAB (UK) Ltd., a KDAB Group company

                    1 Reply Last reply
                    0

                    1/9

                    4 Apr 2011, 15:38

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved