How to navigate to a page in my application after external php file?

I have a contactForm.html page in my ionic application. Once the user presses submit, the form posts to an external php file on my website which can run php. I am able to get the information just fine, but I want to automatically send the user to the home.html page in my application after the php file.

In my php I have tried history.go(-1) which works but just directs me back to contactForm.html. After that, I try window.location.href = "/home.html" or window.location.href = "/app/home" but nothing happens or it gets stuck. If I don’t do history.go(-1)and just do window.location.href = "/home.html" it just directs me to my website’s homepage not the application.

So how do I navigate to a page in my ionic app from an external php file?

I can understand your problem. Even i have several solutions for you.

Solutions-1
When user is pressing the submit button on “contactForm.html”, then just don’t fire the form submit. Rather in-place of submit button use “html buttons only” and after pressing that button call the angular ajax i.e $http to post all your to your page, and after a response in $http success callback you can use $state.go(‘app.home’); to redirect to particular page.

Solution-2
Create a iframe in your ionic html page. So your contactForm.html should be placed on server rather than ionic resources. So that contactForm.html should post to your php page and things can be handled. Even from the ionic itself you can check the iframe state and src base on that you can redirect your page.

1 Like

Thank you! I understand solution 2 and might just do that but is solution 1 better? I have searched endlessly but cannot figure out how to correctly do $http callbacks. Any time I get it kinda working, I get a status code 0. I’ve looked that up and I still don’t understand what I am doing wrong, or is my server just not able to process that request?

Here’s my javascript:
var request = $http({ method : "post", url : "mywebsite.com/pages/contactForm.php", data : { date : $scope.date, time : $scope.time, description: $scope.description } }).then(function successCallback(response) { alert("Success"); // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. alert("error"+response.status); });

The php still works, I get the data into my database, but anytime I run this it alerts “error0”