Abhinav Raja
Abhinav Raja

Reputation: 351

How to pass data to a wordpress website

i am making an android app for a word press website. I am almost done. I am just stuck on a small thing. This is the link for the particular website page i want to make in the app: http://abinet.org/contact-us/ . The user shall fill the required fields and click on submit and the message has to go to website admin (the same way as it happens in the website).

I can make xml layout, get the texts and all but don't have a clue of what to code in the "submit" button. I wasn't able to search on Google about this as i am not sure what exactly to search. i don't know what this is called. I don't want coding. i just want to know what topics i need to read to achieve this. Any start would be helpful.

Upvotes: 1

Views: 540

Answers (2)

Oerd
Oerd

Reputation: 2303

You want to POST data to a WPCF7 form from your android app.

You can search SO or even the web for this but here's some quick tips:

  1. You cannot just POST data like that because wordpress contact form 7 has protection measures agains spam (see: CSRF).
  2. If using wordpress-json-api you can add a function that takes POST data and safely submits them to WPCF7, and map this function to an json-api call

Consider a more durable solution: just for the contact form, you can use a WebView to load http://abinet.org/contact-us/ and inject a custom css to change the look and feel. So just in case the website needs to add more fields, it can do so without breaking your app.

If this seems too complicated, you can make your own custom layout and bind the submit button to a task that: gets the hidden fields from the website and include them when posting.

Update:

Network tasks and all other IO-related tasks should not and cannot (depending on the OS version) be done in the main UI thread. To perform these actions either a new thread is created and run or -- in a more Android way -- an asynchronous task is executed in the background. To make use of an AsyncTask in your "Contact Form Activity":

  • Write an inner class that extends AsyncTask
  • Instantiate and execute it in your activity's onClick(View v) method (for a very good example see how to asynchronously download a webpage)
  • After downloading you'll need a DOM parser to get hidden fields out of the blank form and include them in the POST submission of the contact form.

This will probably not be a detailed solution to your problem, but your problem "is complicated" ;) You now should know how network-related tasks are performed in Android (how to go about performing HTTP POST requests to generic sites) and how to GET form CSRF tokens and other hidden fields (consider all web forms as having them). If you need help with any of these issues please, ask another question.

Upvotes: 2

vico
vico

Reputation: 2142

what you are looking for is andriod sending a post data to a web url

/contact-us/#wpcf7-f595-p444-o1

this is the action url from your current webpage.

make sure to include all the required post values the values to past are their name="xxx" inside the html

Upvotes: 1

Related Questions