2017-02-04 8 views
0

前のページからユーザー入力を抽出して次のページに挿入するにはどうすればよいですか?ここで

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Cookie Order Form</title> 
 
    <link rel="stylesheet" href="First_Design.css"> 
 
    <script src="cookieform.js"></script> 
 

 
</head> 
 

 
<body> 
 
    <h1>Cookie Order Form</h1> 
 
    <p>This form is a cookie order form for customers that purchased cookies from Daron's Cookies Company and the following below must be filled out in order for each customer to receive a final message that tells them when their order will be ready.</p> 
 

 

 
    <IMG class="Wrap1" SRC="cookie.gif" alt="cookie"> 
 
    <IMG class="Wrap2" SRC="cookie.gif" alt="cookie2"> 
 

 

 

 
    <!--The customer will be sent to the HTML page named "submit.html" after they 
 
    click the "Submit this Form" button. The code below does this. --> 
 
    <div> 
 
     <form id="cookie_form" action="submit.html" method="POST"> 
 

 
      <fieldset class="field_set_1"> 
 
       <!-- Below sets the title of the form--> 
 
      
 
       <legend>Customer Order Form Information:</legend> 
 

 

 
       <!-- Creates the first left label to specify what should be placed in the text box 
 
       to the right of the label. The rest below does the same.--> 
 

 
       <label for="firstName">First Name:</label> 
 
       <input type="text" id="firstName" name="firstName"> 
 
       <span id="firstname_error">*</span><br> 
 

 
       <label for="orderNumber">Order Number:</label> 
 
       <input type="text" id="orderNumber" name="orderNumber"> 
 
       <span id="orderNumber_error">*</span><br> 
 

 
       <label for="date_of_order">Date of Order:</label> 
 
       <input type="text" id="date_of_order" name="date_of_order"> 
 
       <span id="date_of_order_error">*</span><br> 
 

 
       <label for="email_address">Email Address:</label> 
 
       <input type="text" id="email_address" name="email_address"> 
 
       <span id="email_address_error">*</span><br> 
 
      <label>&nbsp;</label> 
 
      <input type="button" id="form_submission" value="Submit this form" onclick="submission()"/ > 
 
      </fieldset> 
 

 
     </form> 
 

 
    </div> 
 
    <div class="clearfix"> 
 
    </div> 
 
    <IMG class="Wrap1" SRC="cookie.gif" alt="cookie"> 
 
    <IMG class="Wrap2" SRC="cookie.gif" alt="cookie2"> 
 

 

 
</body> 
 

 

 

 
</html>

私はあなたが見たいと思います送信ボタンです。私はw3schoolsに行きましたが、私の問題には何もありませんでした。次のページに配置する

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>Submission of Form</title> 
 
<link rel="stylesheet" href="second_page_design.css"> 
 

 
// Do I need to use javascript? 
 
</head> 
 
<body> 
 
// But I want this to display different message towards different 
 
user first names. How can this be done? 
 
<p>Thank You + firstname you will recieve your order on February 20, 2017. 
 
Have a nice day!!!!!! </p> 
 

 

 
</body> 
 
</html>

はどのようにして、送信ボタンからユーザ入力の異なる第1名を抽出しますか?

+0

に変更して、フォームを送信してサーバーに入力すると、サーバーは新しいページフォームを処理するサーバーによって生成されたhtmlに提出された入力を含めます...これはフォーム101のものです - 実際の回答はサーバー側の言語に依存します –

+0

どのボタンについて話していますか? JSのコメントと同じです。 –

+0

私の送信ボタンにhtmlページを使用するとJaromanda Xが表示されません。しかし、私はそれについて尋ねていません。 – Joe

答えて

1

あなたはそれが唯一のjavascriptとする必要がある場合は、webstorageオプションのブラウザで見ることができますがあなたを与える:https://developer.mozilla.org/nl/docs/Web/API/Storage

そうでない場合は別のページからのデータを送信するための最も簡単な方法は、PHPを使用しています。 2番目のページの名前を "second-page.php"のように変更すると、サーバがサポートしている場合にそのファイルでPHPを使用できるようになります。
フォーム内のアクションは、そのファイルに設定する必要があります。したがって、action="second-page.php"です。 次に、$_POSTアレイを使用して、必要なデータを抽出することができます。

<?php 
    $firstName = filter_input(INPUT_POST, "firstName"); 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<title>Submission of Form</title> 
<link rel="stylesheet" href="second_page_design.css"> 

// Do I need to use javascript? 
</head> 
<body> 
// But I want this to display different message towards different 
user first names. How can this be done? 
<p>Thank You <?php echo $firstName; ?>, you will recieve your order on February 20, 2017. 
Have a nice day!!!!!! </p> 


</body> 
</html> 

PHPの最初の部分は、フォームからfirstNameフィールドの値を取得し、$ firstName変数に保存します。この段落では、echoを使って変数の値を書き込むことができます。短いPHPタグが有効な場合は、その部分を<?= $firstName ?>

+0

StefanJanssenありがとう!!!!!!!!!!!!! – Joe

+0

それが他の人々がそれを知っているこの方法あなたを助けたら答えとしてそれをマークしてください。 – StefanJanssen

関連する問題