How do I pass php form data to an angular2 app? - php

I'm still quite new to angular2/4 so forgive me if I'm missing something obvious.
I am trying to update a booking process and we are doing this with angular2/4. Currently the booking process starts on a php website, once some basic information is filled out the angular app is supposed to take over. What I'm not sure of is how I'm supposed to take the form data from PHP and receive that data in my angular app.
There is an express.js back end for the angular app, but I don't understand how I would be able to post from the PHP site and return the result to the angular app.
Again sorry, I'm still new to angular so I'm not sure how I should approach this.

Create an API (http://localhost:8080/bookings/) in your existing PHP application which your angular app can access via a GET/POST request using angulars HTTP client. https://angular.io/guide/http.
Or
Alternatively, use the express backend to talk to the MySql DB / Or other DB that your php application is using. Use express as an API similar to the above or simply render the page with the data obtained from the DB. https://expressjs.com/en/guide/database-integration.html

Related

Send data from vue.js project to a api/file.php inside it

Hello I'm trying to send data to an api/file.php inside my Vue project that inserts data sent into a database. I'm getting an error
This is the code for the request... Made from App.vue to api/recipes.php who's one level above.
The code I was using worked in an example where I made index.php with vue.js and an api/file.php file and used them to communicate with the database. I'm uncertain I know how to access my api on a route? Not even certain if I'm asking the right question. Thank you!
EDIT ////
I started the server # localhost:8080 on the back-end that I'm trying to get the data from. There I have a get method that serves all data from the database and display as JSON with json_encode($variable). When trying to make the request I'm getting a CORS error.
https://prnt.sc/tzvbhh

How To integrate Angular 4 With Php frontend (Existing Project) for page Rendering and backend Nodejs

i have to integrate Angular 4 in my existing Php(Codeigniter) Project but i am not able to find right way to integrate angular 4 . any one know this process.please Share
If you are using node.js for backend. You wont need Php. It will be just NodeJs and Angular.
Without NodeJS, You can use Php to write your APIs and have front-end in Angular which will call those APIs using HttpClinetModule.
If you want to use Angular4 you should remake the frontend in Angular4.
Then on your NodeJS backend create rest routeshttp://localhost:3000/tasks for example would return a JSON object.
Then connect to your NodeJS route (http://localhost:3000/tasks) (from angular) using HttpClientModule and it'll return a JSON object then return that data from your service to a component that you want to display the data in, and either subscribe to it in the component or use the async pipe to unpack the data.
P.S you could also use your current PHP project and make that into an API.

How to convert this PHP CURL to Angular $http.post?

At https://github.com/apanzerj/Former-For-Zendesk/blob/Lesson-1-Branch/former.php there is a Zendesk repository for sending the contents of a custom HTML contact form to Zendesk's server.
I'm building an AngularJS website and I'd like to have this same functionality but using Angular's $http.post method instead of PHP CURL.
I'm at a loss on how to convert their thing from PHP to Angular though. Any tips would be greatly appreciated!
Is it even possible to go from AngularJS directly to Zendesk's server, without a server-side language on my end that passes the data?

PHP app the retrieves constantly changing or new data

How would one develop a PHP app that would constantly update the current state of a webpage? Is there some sort of a pattern that can be implemented to achieve this? What would be the ajax programming needed to update the state of what a web page shows?
The basic idea is that of the Facebook news feed where the page is constantly changing as new data gets entered or data is modified.
Why don't you just make API call.
or
Have a look at their documentation: https://developers.facebook.com/docs/php/gettingstarted/

Submit form using webservice

I am building a form on my website. I want to save the details into some other database/website using some exposed web service from the other website. How can i do this. I have no idea about this. Can you give some steps on how to do it.
Are you looking to build the "client" end (server with the form), "server" end (webservice receiving details) or both?
Client can use php_curl or similar to send data to a REST webservice on the server
So something like this
User (fills out form) -> Frontend-server (PHP) -- [sends request with information] --> Backend-server (saved)
So a user would theoretically send to the frontend server data data data
The frontend server (PHP) uses curl to send the info to the backend server http://backend.server.com/heres-some-info.php?data=data%20data%20data
The backend server will save/process the data as appropriate
Assuming the website is with some hosting service (like godaddy.com), it will have support for MySQL database and a server side language - like PHP/Python, etc.
Make a form using the server side language which inserts values into the database.
Send data to the form from the app.

Categories