2017-10-06 89 views
0

我需要在我的Android應用程序WebView中顯示iframe,iframe存在於位於Web服務器上的HTML文件中。 我需要添加一個參數到iframe源,然後在WebView中顯示它,具體取決於用戶輸入。將參數添加到iframe源

我的PHP代碼:

<?php 

    if (isset($_POST['amount'])){ 
     $amount = $_POST['amount']; 
     $intamount = (int)$amount; 
     echo $intamount; 
    } 

    if (isset($_POST['currency'])){ 

     $currency = $_POST['currency']; 
     $intcurrency = (int)$currency; 
    } 

    if (isset($_POST['lan'])){ 

     $lan = $_POST["lan"]; 
    } 

    if (isset($_POST['email'])){ 

     $email_address = $_POST["email"]; 
    } 

    if (isset($_POST['name'])){ 

     $name = $_POST['name']; 
    } 




    $iframe_source = 'https://sampleurl.php?sum='.$intamount.'&currency='.$intcurrency.'&cred_type=1&trButtonColor=008080&email='.$email_address.'&contact='.$name; 

    echo $iframe_source; 

?> 

<!DOCTYPE html> 
<html> 

    <head> 
     <meta charset="utf-8"/> 



    </head> 

    <body> 


     <iframe width="370" height="455" src="<?php 
      echo $iframe_source; 
     ?>" frameborder="5" allowfullscreen></iframe> 

    </body> 

</html> 

我可以做一個POST請求的PHP文件,例如要做到這一點?如果是的話,有沒有辦法在PHP文件中添加html代碼並將其顯示在我的WebView中? 有沒有更好的方法來做到這一點? 非常感謝。

+0

這不是一個真正的來源,它只是一個例子,我需要能夠根據用戶輸入來調整它來回我的Android應用程序 –

+0

當然,sampleurl只是一個例子,真正的是你提供的格式,它工作正常,我猜是在接收參數之前顯示iframe,這可能是我得到該錯誤的原因 –

回答

1

爲什麼不在接收用戶輸入後加載PHP表單到您的Web服務器。

您可以執行POST或GET請求。

所以裝載的instate http://example.com/webview.htmlhttp://example.com/webview.php?user_paramter=value

現在webview.php外觀基本相同ES的webview.html有一些小的變化:

<?php 
    $user_paramter = $_GET['user_paramter']; 
    $link = 'https:iframedemo.php?sum=13&currency=1&user_paramter=' . $user_paramter; 
?> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"/> 
    </head> 
    <body> 
     <iframe width="370" height="455" src="<?php 
      echo $link; 
     ?>" frameborder="0" allowfullscreen></iframe> 
    </body> 
</html> 

您的應用程序將收到有權iframe的HTML文件源/鏈接

如果這個PHP腳本在用戶輸入之前被收回,那麼比$_POST$_GET是空的,什麼也不是 將工作。所以如果你在你的PHP腳本開頭做var_dump($_POST),並且你有類似array(0) {}的問題,那麼問題不是PHP腳本或iframe本身。您必須找到用戶輸入後調用頁面的方式。

+0

也許你可以刪除問題和答案上的所有命令所以洞的東西看起來不那麼亂 – Webdesigner