Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP中的google API生成QR码,并使用表单发送的数据?_Php_Jquery - Fatal编程技术网

使用PHP中的google API生成QR码,并使用表单发送的数据?

使用PHP中的google API生成QR码,并使用表单发送的数据?,php,jquery,Php,Jquery,这是functions.php文件: <?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页面上生成二维码

这是functions.php文件:

<?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页面上生成二维码

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


请帮忙!提前感谢。

首先,您需要运行您的函数。现在它被宣布了,但你什么也不做

下面是一个如何实现的示例:

<?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']);

虽然@jdrzejb的这种方法更准确,但我们真的不知道什么是
$qr->qrCode()可以。还有,
url($_POST['number'],$_POST['sub'])只检查参数是否为空。这个函数不做更多的事情。在哪里使用
$\u POST
参数仍然很模糊。所以这个答案应该得到改进。另外,超全局函数已经在函数范围内可用,所以没有理由通过函数参数传递它们。证明:
if(isset($_POST['number']) && isset($_POST['sub'])) {
    url($_POST['number'], $_POST['sub']);
}