fnobi / php-express

enable express server to exec php.
36 stars 15 forks source link

Form POST doesn't work #6

Open drew-wallace opened 9 years ago

drew-wallace commented 9 years ago

I tried making a simple form that prints the $_POST array on submission:

<html>
<head>
        <meta charset="UTF-8">
</head>
<body>
<?php
        if(isset($_POST['uname'])) {
                print_r($_POST);
        }
?>
<form action='http://example.com/current_page.php' method='post'>
Username:<br>
<input type='text' name='uname'><br>
Password:<br>
<input type='password' name='pword'><br><br>
<input type='submit' value='Submit'>
</form>

</body>
</html>

It never sends off the data. Any ideas?

drew-wallace commented 9 years ago

I have it working now. I'll make a pull request today. I have to figure out how to do it first...

nevyen commented 8 years ago

Hey @drew-wallace can you explain how you solve the problem?

In my code I doesn't send the data directly from the form, I send it from a service with $http.post(); But it seems that no data arrives in the php file.

drew-wallace commented 8 years ago

@nevyen It's been almost a year since I've looked at this. If you checkout my repo, you will find that I made it work. For the life of me I can't remember what I changed :stuck_out_tongue:

nevyen commented 8 years ago

@drew-wallace I have looked at your repo and looked into the server.js. You use the same lines I do:

// must specify options hash even if no options provided!
var phpExpress = require('php-express')({

  // assumes php is in your PATH
  binPath: 'php'
});

  // set view engine to php-express
  app.set('views', config.root);
  app.engine('php', phpExpress.engine);
  app.set('view engine', 'php');
// routing all .php file to php-express
  app.all(/.+\.php$/, phpExpress.router);

Can you help me to figure this out? Maybe you have an idea what to look for or where?

I looked at your repo and look into the php-express folder. You have changes in page_runner.php and in engine.js.

drew-wallace commented 8 years ago

Changes: engine.js page_runner.php

It looks like the dev is actively working on this. I would ask him if what's up.

nevyen commented 8 years ago

That would be nice thanks ;)

nevyen commented 8 years ago

Hey @drew-wallace do you have any information for me? For now the project is getting bigger and it's a little annoying to upload the app each time.

drew-wallace commented 8 years ago

Unfortunately no news. What exactly are you trying to do? If you are really trying to run a PHP server using node, I don't advise it. This was something I was just messing around with to see if it was possible. The problem with this method is that it executes the PHP on the command line and that means that any javascript will not execute.

nevyen commented 8 years ago

Okay what I am trying to do is: We are developing an angular app but the server side is written in php. In my local devenviornment I use express with grunt to watch file changes and so on. So I need a possibility to test my requests against the php files. All get-request are no problem. But angular seems to put post-data into php://input and this isn't read by php-express.

I know it is possible to use a local apache to serve the php files but I don't want to compile the whole angular app if I change a few lines of code.

Does this explanation helps to understand what I am trying to do? If there are any questions feel free to ask.

Thanks for your support

drew-wallace commented 8 years ago

If your app is small, it might be wise to convert your PHP into node. If that's not possible, I can take a look at this repo this weekend and see if I can figure out what's going on. If you could create an example form like the one I have at the top of this issue, then I will have something to test against.

nevyen commented 8 years ago

Hey I am very sorry but yesterday I had no computer to my hand.

I found this example and add the $http function.

<!DOCTYPE html>
<html ng-app>
<head>
<title>Hello World, AngularJS - ViralPatel.net</title>
<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
<div ng-controller="ContactController">
     Email:<input type="text" ng-model="new contact"/
    <button ng-click="add()">Add</button>
    <h2>Contacts</h2>

    <ul>
        <li > {{ contact }} </li>
    </ul>

</div>
<script type="text/javascript">
    function ContactController($scope, $http) {

        $scope.add = function() {
 var data = {
        mail: $scope.newcontact
      };
        $http.post(urlToPhPScript, data).then(response => {
        return response.data;
      });
        }
    }
</script>
</body>
</html>

My Php Script looks something like this:

$bestellung = json_decode(file_get_contents("php://input"));
//$bestellung = json_decode('{"rechnung":"24h-2","mail":"testfrau@musterfrau.de"}');

$db = getConnection();
header('Content-type: application/json');
        header('Cache-Control: no-cache, must-revalidate');
saveToDb($bestellung->{'mail'})

The server is given to us for low so we have no root access and we can't and won't run a node server. So we have to use php under apache.

I hope this example is enough to work with it.

Thanks again for your help.