2010-01-16 74 views
0

我是PHP新手。 Iv創建了一個小的PHP腳本。基本上,我有一個表格和它內部的我已呼籲show_sent功能:如果有PHP,只顯示錶格

 <form method="post" action="contact.php" class="formstyle"> 
      <h2>Formulaire de contact : </h2> 
      <p>&nbsp;</p> 

    <? 
function show_sent(){ 
    ?> 
    <p>Sent</p> 

      <? 
} // the function finishes here 
?> 

.......

我希望它只會顯示,當我稱之爲「已發送」文本該功能。我怎麼能這樣做? 感謝

contact.php是在同一個頁面的形式

+0

我猜你想在某人使用該表單後顯示此消息(「已發送」)。那麼你應該提供給我們更多關於'contact.php'的信息,因爲它是你發送表單的文件。 – kjagiello 2010-01-16 19:36:19

+0

基本上如果有東西,如果(!$ _ POST){do_function(); die();}它會做的東西包括顯示文本 – jmasterx 2010-01-16 19:39:37

+0

確定其打印我看到感謝 – jmasterx 2010-01-16 19:40:59

回答

4

你需要清理一下你的代碼。跳入和跳出HTML和PHP並不是一件好事。

+0

我認爲最好從函數返回字符串,而不是直接回顯函數。所以我會有'<?php 函數show_sent(){ return「Sent」; ',然後回顯出結果:'<?php echo「」.show_sent()。「」;「 }?> ?> – carbocation 2011-09-28 20:15:15

0

你需要檢查,看看是否表單數據公佈。

if(isset($_POST['form_element_name'])) 
{ 
    //call the show_sent function because data has been posted 
    show_sent(); 
} 

做的是發佈形式的自我,而不是另一個文件,那麼你可以檢查變量他們,如果有數據
function show_sent(){ 
    if(isset($_POST['form_element_name'])) 
    { 

    } 
} 
//Call the show_sent function all the time because the code inside the function checks the POST variables. 
show_sent();