2016-02-02 34 views
-3

我有一个表单上提交我想要它做的两件事情: 1)存储值在数据库 2)写$ _ POST值到PD​​F如何在php中提供多个“提交”按钮?

我对数据库的脚本编写和它的工作原理在其自己的。我有另一个写入PDF的脚本,它也可以正常工作。

但是,当我尝试在另一个结束时调用一个函数时,提交操作仅执行其中一个操作。我该如何解决这个问题。我希望我的按钮同时执行store.php和makepdf.php

目前,我只能在表单的action标签中指定一个表单。

编辑:我在这里添加脚本。

这里是(串联为长度的限制)我store.db文件:

<?php 

    $dbhost = 'localhost'; 
    $dbuser = ''; 
    $dbpass = ''; 

// GET ALL THE VARIABLES FROM THE FORM 

    $FirstName= $_POST['firstname']?$_POST['firstname']:'0'; 
    $LastName= $_POST['lastname']?$_POST['lastname']:'0'; 
    $Email= $_POST['email']?$_POST['email']:'0'; 
    $idn= $_POST['idn']; 

    $conn = mysql_connect($dbhost, $dbuser, $dbpass); 

    if(! $conn) { 
     die('Could not connect: ' . mysql_error()); 
    } 

    $sql1 = "INSERT INTO borrower(FirstName,LastName,Email,ssn) VALUES('".$FirstName."','".$LastName."','".$Email."','".$idn."); 
    mysql_select_db('db'); 
    $retval1 = mysql_query($sql1, $conn); 

    } 

//Test successs 
    //echo "Successful" 

?> 

这里是我的makepdf.php:

<?php 

function pdfMaker() { 
include('fpdf/fpdf.php'); 
include('fpdi/fpdi.php'); 

$FirstName; 
$LastName; 
$Email; 
$IDNumber; 



// initiate FPDI 
$pdf =& new FPDI(); 
// add a page 
$pdf->AddPage(); 
// set the sourcefile 
$pdf->setSourceFile('rcpp1.pdf'); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
// use the imported page as the template 
$pdf->useTemplate($tplIdx, 0, 0); 

// now write some text above the imported page 
$pdf->SetFont('Times', '', 9); 
$pdf->SetTextColor(0,0,153); 

// Top Left stuff 
$pdf->SetXY(9, 38); 
$pdf->Write(0, $Firstaname.$LastName.$Email.$IDNumber); 

$pdf->Output(($Firsname."_".$Lastname.'file.pdf'), 'D'); 

} 

pdfMaker(); 

?> 

这里是我的表格:

<form class="form-horizontal" method="post" action=""> 
<fieldset> 

<!-- Text input--> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="firstname">First Name</label> 
    <div class="col-md-4"> 
    <input id="firstname" name="firstname" type="text" placeholder="" class="form-control input-md"> 

    </div> 
</div> 

<!-- Text input--> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="lastname">Last</label> 
    <div class="col-md-4"> 
    <input id="lastname" name="lastname" type="text" placeholder="" class="form-control input-md"> 

    </div> 
</div> 

<!-- Text input--> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="email">Email</label> 
    <div class="col-md-4"> 
    <input id="email" name="email" type="text" placeholder="" class="form-control input-md"> 

    </div> 
</div> 

<!-- Text input--> 
<div class="form-group"> 
    <label class="col-md-4 control-label" for="idn">ID#</label> 
    <div class="col-md-4"> 
    <input id="idn" name="idn" type="text" placeholder="" class="form-control input-md"> 

    </div> 
</div> 

</fieldset> 
</form> 

再次,当我添加任何PHP脚本的形式在行动标签,每个功能单独罚款。但是,如果尝试向另一个脚本添加一个函数或从另一个脚本调用它,它只会执行一个并停止。

+1

,而不能看到你的代码中,我们只能推测....我们不这样做非常好。 –

+0

首先我包含所有三个脚本? – Tendi

+0

表单一次只能提交一个网址。你为什么要“提交按钮”做两件不同的事情?是不是表单提交给任何形式的工作?这个脚本是'<?php job1();这是微不足道的。 JOB2(); ?> –

回答

-1

只需包括在另一个在PHP一个脚本:

store.php脚本试试这个:

include("makepdf.php"); 

仅供参考,您也可以从另一个调用一个脚本,但你需要通过后的参数以及文件名如下:

file_get_contents("makepdf.php?param1=".$_POST['param1']."&param2=".$_POST['param2']); 
+0

为什么downvote? – cronoklee

+0

我不知道谁低估了你,我不认为这是我。我已经更新了我的脚本。 – Tendi

+0

别担心。你有没有尝试包括? – cronoklee

0

您是指<form action="/uri" >

<form action="/path/to/do_two_things.php" >怎么样?

<form action="/path/my_form_handler.php"> 
    <input type="submit" name="dowhat" value="Do action A" /> 
    <input type="submit" name="dowhat" value="Do action B" /> 
</form> 

<?php 
if ($_POST['dowhat'] == "Do action A") { 
    // something 
    // even more than one thing 
} else { 
    // something else 
    // etc 
} 
?> 
+0

我已经更新了我的脚本。 – Tendi