php - Android post html data using a form -
i made app receives 3 text fields , needs send data website. have looked @ php code of main page , since i'm not php, i'm not sure how post data. here how form looks on site:
<div id="tzgb-homesearch-wrap"> <div id="tzgb-homesearch"> <form method="post" action="http://www.online-bustickets.de/bus-departure-destination/"> <input type="hidden" id="_searchbox" name="_searchbox" value="77e642a333"><input type="hidden" name="_wp_http_referer" value="/"> <div class="search-row"> <label for="von">von</label> <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><input type="text" id="von" name="von" placeholder="abfahrtsort eingeben" class="ui-autocomplete-input" autocomplete="off" mouseev="true" keyev="true" style="background-image: url(data:image/png;base64,ivborw0kggoaaaansuheugaaabaaaaaqcayaaaaf8/9haaabhkleqvq4eavto26dqbd1ohqwas2lg9jybz+ak7hnwx2oiovf4upq0lj1fdkktevipel8aknukdcwmxpgsaieatvv3sx7uztitdu2s/98dywow3dued4who/m2aix5lzv1aesy0+qiwhelyi+ytl0pq69sxaxkwia4rmrtdnske59jumcuzd6xiafez6fgcdj8ky4y7kautrngd7jyebxsdope3a0qgpsnionnymo67lgsqn9t41f2qgrqrrfcwyzoif2qybukkbcogpxdvey9rmwgnsjf9ccyesjhk3f5dyt1hx9gr0llqr30tnjkuecx2uius4rni+aj6sjr0am8aaumpam/rrehywhxqbfaa9kh3/8/nvhxaygasz/il8ialkclbfnvaaaaabjru5erkjggg==); padding-right: 0px; background-attachment: scroll; cursor: auto; background-position: 100% 50%; background-repeat: no-repeat no-repeat;"> <input type="hidden" id="von-permalink"> </div> <div class="search-row"> <label for="nach">nach</label> <span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><input type="text" id="nach" name="nach" placeholder="zielort eingeben" class="ui-autocomplete-input" autocomplete="off"> <input type="hidden" id="nach-permalink"> </div> <div class="search-row"> <label for="datum">datum</label> <input type="text" id="datum" name="datum" readonly="readonly" class="hasdatepicker"> </div> <div class="submit"> <input type="submit" id="tzgb-homesearch-submit" value="suchen"> </div> </form> </div> </div>
my app need submit form using values entered in text fields. problem have doesn't use script.php file when submits, uses function class. here's code home.php:
<div id="tzgb-homesearch-wrap"> <div id="tzgb-homesearch"> <?php if ( class_exists( 'tzgb_busroute' ) ) global $tzgb_page_template; $tzgb_page_template->homesearch(); ?> </div> </div>
and here code function homesearch():
function homesearch() { ?> <form method="post" action="<?php bloginfo( 'url' ) ?>/bus-departure-destination/"> <?php wp_nonce_field( $this->noncekey, $this->noncefield ); ?> <div class="search-row"> <label for="von">von</label> <input type="text" id="von" name="von" placeholder="abfahrtsort eingeben" /> <input type="hidden" id="von-permalink" /> </div> <div class="search-row"> <label for="nach">nach</label> <input type="text" id="nach" name="nach" placeholder="zielort eingeben"/> <input type="hidden" id="nach-permalink" /> </div> <div class="search-row"> <label for="datum">datum</label> <input type="text" id="datum" name="datum" readonly="readonly" /> </div> <div class="submit"> <input type="submit" id="tzgb-homesearch-submit" value="suchen" /> </div> </form> <?php }
so, how post data website? need return webpage displayed in webview.
update code looks now:
httpclient httpclient = new defaulthttpclient(); httpconnectionparams.setconnectiontimeout(httpclient.getparams(), 10000); httpconnectionparams.setsotimeout(httpclient.getparams(), 10000); httppost httppost = new httppost( "http://www.online-bustickets.de/bus-departure-destination/"); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("_searchbox", "5624dd9868")); namevaluepairs.add(new basicnamevaluepair("_wp_http_referer", "/")); namevaluepairs.add(new basicnamevaluepair("von", "berlin")); namevaluepairs.add(new basicnamevaluepair("nach", "alsfeld")); namevaluepairs.add(new basicnamevaluepair("datum", "12.03.2014")); // etc... try { httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); content = entityutils.tostring(response.getentity()); log.i("test", "" + response.getstatusline().getstatuscode()); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
but when try open in webview page saying value von , nach not in database. have ideas problem might be?
update1 error message on site when search without entering values. link error: http://www.online-bustickets.de/bus--/
i found answer. problem httppost link. website using custom link one: http://www.online-bustickets.de/bus-berlin-behringersmuehle/
so fields von , nach must added link every time. working code:
private class customtask extends asynctask<void, void, void> { @override protected void doinbackground(void... param) { // work log.i("test", "working"); autocompletetextview textview = (autocompletetextview) findviewbyid(r.id.edittext_von); string von = textview.gettext().tostring(); autocompletetextview textview1 = (autocompletetextview) findviewbyid(r.id.edittext_nach); string nach = textview1.gettext().tostring(); edittext datumtext = (edittext) findviewbyid(r.id.edittext_datum); string datum = datumtext.gettext().tostring(); httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost( "http://www.online-bustickets.de/bus-" + von + "-" + nach); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("_searchbox", "5624dd9868")); namevaluepairs.add(new basicnamevaluepair("von", von)); namevaluepairs.add(new basicnamevaluepair("nach", nach)); namevaluepairs.add(new basicnamevaluepair("datum", datum)); // etc... try { httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); inputstream = response.getentity().getcontent(); log.i("test", "response status" + response.getstatusline().getstatuscode()); inputstreamreader inputstreamreader = new inputstreamreader(is); bufferedreader bufferedreader = new bufferedreader( inputstreamreader); stringbuilder stringbuilder = new stringbuilder(); string bufferedstrchunk = null; while ((bufferedstrchunk = bufferedreader.readline()) != null) { stringbuilder.append(bufferedstrchunk); } content = stringbuilder.tostring(); log.i("test", "content " + content); } catch (unsupportedencodingexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return null; } protected void onpostexecute(void param) { // print toast or open dialog intent intent = new intent(getbasecontext(), webviewactivity.class); intent.putextra("site_content", content); startactivity(intent); } }
Comments
Post a Comment