2017-04-10 47 views
0

这是functions.php文件:用PHP中的Google API与从Form发送的数据生成QR码?

<?php 
    include 'QR_BarCode.php'; 
    function url(){ 
     $qr = new QR_BarCode(); 
     $qr->url('here i want data sent from form'); 
     $qr->qrCode(); 
    } 
?> 

这是我的HTML表单的index.php。我想在index.php页面上生成QR码。

<form method="post" id="form_id" action="functions.php"> 
    <input type="tel" name="number"> 
    <input type="submit" id="sub" name="sub"> 
</form> 

Here is the link I generate qr codes from.

请帮帮忙!提前致谢。

回答

1

首先,您需要运行您的功能。现在它被宣布了,但你什么都不做。

下面是一个例子如何可以做到:

<?php 
include 'QR_BarCode.php'; 

function url($number, $sub){ 

    if(empty($number) || empty($sub)) { 
     die('Error. Fields cannot be empty'); 
    } 

    $qr = new QR_BarCode(); 
    $qr->url(); 
    $qr->qrCode(); 
} 

// This is only example. You should validate those inputs. 
url($_POST['number'], $_POST['sub']); 

但请记住,如果没有$_POST数据运行的functions.php将导致PHP的通知。您可以为$_POST值的检查中要求,然后才运行此功能

if(isset($_POST['number']) && isset($_POST['sub'])) { 
    url($_POST['number'], $_POST['sub']); 
} 
+0

虽然@jdrzejb的这种方法更准确,我们真的想不通,是什么'$ QR-> QRCODE(); '确实。而且,'url($ _ POST ['number'],$ _POST ['sub']);'只是检查参数是否为空。这个功能没有其他功能。在哪里使用'$ _POST'参数仍然是模糊的。所以这个答案应该改善。 –