【问题标题】:Silex basic form submissionSilex 基本表单提交
【发布时间】:2013-04-11 18:16:27
【问题描述】:

我正在尝试向我的网站添加支付网关。我在 Silex 框架的基本实现方面遇到了很多麻烦。永远找不到app.php 页面。事实上,我目前正在使用测试服务器,而 signup.php 页面位于以下目录中:

http://localhost/www/smafo/signup.php,

提交表单最终会导致以下 url http://localhost/create_transaction 导致页面未找到错误。

注意:将表单的 action 属性更改为 app.php,路由到正确的 app.php 页面并导致 Symfony Page not found 错误。

有什么想法我在这里做错了吗?

这是示例表单:signup.php

<form action="/create_transaction" method="POST" id="braintree-payment-form">
     <p>
       <label>Card Number</label>
       <input type="text" size="20" autocomplete="off" data-encrypted-name="number" />
     </p>
     <p>
       <label>CVV</label>
       <input type="text" size="4" autocomplete="off" data-encrypted-name="cvv" />
     </p>
     <p>
      <label>Expiration (MM/YYYY)</label>
      <input type="text" size="2" data-encrypted-name="month" /> / <input type="text" size="4" data-encrypted-name="year" />
    </p>
    <input type="submit" id="submit" />
 </form>

这是我的 app.php(与 signup.php 在同一目录中)

$app = new Silex\Application();

$app->get('/', function () {
    include 'signup.php';
    return '';
});

$app->post('/create_transaction', function (Request $request) {
  echo 'YES';
  $result = Braintree_Transaction::sale(array(
    'amount' => '1000.00',
    'creditCard' => array(
      'number' => $request->get('number'),
      'cvv' => $request->get('cvv'),
      'expirationMonth' => $request->get('month'),
      'expirationYear' => $request->get('year')
    ),
    'options' => array(
      'submitForSettlement' => true
    )
  ));

  if ($result->success) {
    return new Response("<h1>Success! Transaction ID: " . $result->transaction->id . "</h1>", 200);
  } else {
    return new Response("<h1>Error: " . $result->message . "</h1>", 200);
  }
});

$app->run();

我非常感谢任何建议。

非常感谢!

【问题讨论】:

标签: php forms frameworks routing silex


【解决方案1】:

我遇到了同样的问题,最终通过以下替换解决了它:

<form action="app.php/create_transaction" method="POST" id="braintree-payment-form">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2023-04-01
    • 1970-01-01
    • 2014-02-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多