I have a form that will be posted to a PHP method. However before it is posted I want to pull some information from a 3rd party api service that returns an xml and use that xml to populate my <select> box.
Mostly I was thinking I would be doing this using JS but it turns out Same Origin policy denies pulling xml from remote apis. So now Im stuck.
I render the HTML form user inputs their api credentials the press the button pull data this should call a JS method that would parse the XML from the API and then populate the <select> box on the form and then the user can submit the form it self.
How can I go about this if the API only serves XML and JS has the Same Origin Policy.
You cannot make cross domain AJAX calls for XML... There are some work arounds though. Try this out..
http://benalman.com/projects/php-simple-proxy/
Please check it out, HTML5 CORS methods
http://www.html5rocks.com/en/tutorials/cors/
Related
Ok, I have a unique issue. I have a real estate wordpress website that uses IDX (Internet Data Exchange) data to show MLS (Multiple Listing Service) listings. So all the IDX data is stored through my IDX provider's site. Currently, when a user submits a form, it goes to a results page that is hosted through my idx provider (example: http://www.mysite.idxco.com/idx/my.account#/results.php?). What I am trying to do is create a form which would render the results on the same page....how would I do that? If I am not being clear enough please let me know.
If I understand what you mean, you have different options, you can
1) POST via ajax, and have your hosted page send back html in response that you can show in the same page in a div. Its very easy to do with jquery. It might be easier to integrate in a wordpress page, but you need to be able to modify your hosted page.
2) you can post to a page on your server (not on the idx provider's), then use curl to send the data you received from your form as a post to the idx provider page, grab the returned html, parse it, get the results, reload the page with your own form along with the results you got from curl.
You might need to check with your idx provider if it is ok that you 'scrape' the data.
(Of course if you had a api access which is very likely with idx you can just send a api request, which would be much more efficient )
I am wanting to build an API first RESTful application in PHP. I have never attempted to do this so I have some questions about how to handle PUT and DELETE
So for an example if I have a API endpoint that updates a User profile, should I make it accept BOTH a POST and PUT Request?
If I was building a Client for my API as a Desktop app or iOS app, etc it would be easy to send a PUT request to my API but I plan to have a Web based app for my API as well.
So on my web based app, I would have an HTML Form to Update a User profile, this would then be sent as a POST as HTML Forms do not allow PUT requests.
Could someone with more experience with this explain the best way to handle my example scenario?
Would the proper way be to send my Form as a POST to my PHP script, then my PHP script would make a proper PUT request to my PHP API with cURL?
You can absolutely also do PUT requests from browsers, but you need javascript.
Generally I would say a good way to think about it, is as follows:
First build a great REST api that follows all the rules. Only once you are at that point, think about the workarounds you need to make it work in other contexts. Submitting an HTML form is a valid thing to need a workaround for.
However, since 'POST' is completely open for interpretation, and has little rules associated, one option would be to create a single resource (or url) on your server that handles all the POST requests coming from browsers. (something like /browserpost).
You could always add a hidden <input> field with name="url" that specifies which resource was actually intended to be updated, and an <input> with name="method" value="PUT" for the intention.
You will need to add CSRF protection anyway, so I feel this would be a solid way to deal with this this. 1 endpoint to specifically 'proxy' html-based form submissions and internally do the appropriate mappings to the correct REST services.
I would use GET POST PUT DELETE as they are described in HTTP. That's restful (in my opinion). As regular browser forms does not support this I would send the data via AJAX.
If you really need to use browser forms, maybe because javascript is not enabled, then using POST requests with a param like ?method sounds like a suitable solution - although I don't like it.
i use zend framework and work with some web services(insert, update, delete but with int, string parameters). Now i don't how to upload file(for example image) with zend and web services(REST). Does anyone have some example?
You should send the file throught post call. The Rest service will receive the postAction as when you do what ever other functions. But, with files you cannot make the calls with ajax, so you have a little trick to do in client side.
Remember, REST service will implement post action and receive the parameters as you would receive normally. If you know how to receive and manipulate a file with standard php, you can do it in REST service implementation.
The trick on client side is to create an invisible iFrame and redirect the submit form target to it.
This links explain this method very well with code samples:
form POST in iframe without affecting history
http://ajaxpatterns.org/IFrame_Call
http://geekswithblogs.net/rashid/archive/2007/08/01/Create-An-Ajax-Style-File-Upload.aspx
http://www.openjs.com/articles/ajax/ajax_file_upload/
http://viralpatel.net/blogs/2008/11/ajax-style-file-uploading-using-hidden-iframe.html
NamastĂȘ !!
i am designing a project in phonegap with android. i want to make a login page. i have stored my database in mySql in XXamp. user will enter name and password validation should be done by php page. after validation on php page, php page will send feedback, according to that feedback phonegap screen message whether user is valid or unvalid. please suggest me how can i access php page from phonegap application. I need help.
Thank you in advance.
Similar questions were asked before take a look at this LINK
All your PHP code will have to reside in a remote server.
However using phonegap you can load a website that runs PHP
To get data from the server you have to use the XMLHttpRequest object or jquery's $.get() or $.post() functions.
You will get lot of examples pls google abt $.get() or $.post() functions.
i read the documentation of linkedin inviter from the link http://developer.linkedin.com/docs/DOC-1012 and there is no other help on internet inspite of this page. but what i found is only the XML things on this page. i dont know how to use it and what should be required basically to make the code work. please post or give reference to a complete code for linkedin invitation in PHP. i would greatly be obliged .
There is a LinkedIn-recommended library for PHP that has a specific invite() method that you could use:
http://developer.linkedin.com/docs/DOC-1255
Direct link to code:
http://code.google.com/p/simple-linkedinphp/
Essentially, you pass it the method of invitation (by email, member id), pass it the recipient, subject, message, and it creates the XML and sends it via OAuth to LinkedIn.
There's also a demo script included, and a live demo showing how to use the invite() method here:
http://simplelinkedin.fiftymission.net/
OK I took a brief look at that API you are talking about. The API requires that you first build a XML file and then use the "POST" method to send it to the provided URL. I should mention that I have never attempted this before, so I may be incorrect, but the process seems pretty straightforward, if somewhat confusing according to the LinkedIn API docs.
So you have several options:
I believe that you can use AJAX to post the XML to the LinkedIn API. In order to do this, you would set up an AJAX call that uses the "POST" method. Here is a link on how to construct a AJAX POST request (its a little different than a "get" request). So essentially you would take your users input out of a form, pack it into a series of structured XML nodes (just like if you were building a XML file) and then take that dynamically generated block of XML and insert it into the body of the AJAX request. Send the request and then parse the results.
Alternatively you could set up a blank XML "template" file with the structure you need to submit the invitation to the LinkedIn API. When your user submits the invitation request to your server you would extract their input, validate it, and then use a combo of PHP Xpath and PHP DOM to search through your XML template and dynamically add the user data to the template at the correct node locations. Then use these instructions on this page to send your invitation request to the API handler at LinkedIn (uses PHP function "curl()").
Let me know how it turns out!
Regards,
H