How to send the value of the prompt field to the PHP handler on the server to send the message.

For this I wrote the code, but something is missing, the handler does not see the value of the prompt field.

HTML form

<form style="display:none;" id="myform" action="mailer.php" method="POST"> <input type="email" name="email" id="email" value="" /> </form> 

Javascript

 var email = prompt("Ваш e-mail", "@"); if (email != 'undefined') { document.getElementById("email").value; document.forms["myform"].submit(); } 

Php

 if (isset($_POST['submit'])){ //получаем e-mail $email = $_POST['email']; $email = trim($_POST['email']); $email = strip_tags($_POST['email']); $email = htmlspecialchars($email); //проверка пустого поля if (empty($_POST['email'])) exit(); //фильтр e-mail if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { exit(); } //проверка e-mail if (!preg_match("/[0-9a-z_]+@[0-9a-z_\-^\.]+\.[az]{2,6}/i", $_POST['email'])) exit(); mail(...); mail(...); 

Question: How to send the value of the prompt field to the handler?

Closed due to the fact that off-topic participants are Visman , Peter Olson , Dmitriy Simushev , aleksandr barakin , fori1ton Aug 28 '15 at 10:46 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Visman, Peter Olson, Dmitriy Simushev, aleksandr barakin, fori1ton
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    Assign a value from the javascript variable to the element on the page. Here

      document.getElementById("email").value; 

    do not perform any actions. Make the assignment

      document.getElementById("email").value = email; 

    UPD

    Working example (file 1.php)

     <?php header('Content-type: text/html; charset=utf-8'); if (isset($_POST['email'])){ var_dump($_POST); exit(); } ?> <form style="display:none;" id="myform" action="1.php" method="POST"> <input type="text" name="email" id="email" value="" /> </form> <script> var email = prompt("Ваш e-mail", "@"); if (email != 'undefined') { document.getElementById("email").value = email; document.getElementById("myform").submit(); } </script> 
    • Visman, I have already done so. Only onClick here in the window. - Viher
    • @Viher, added a working example to the response. - Visman
    • thank! I found I saw my error if (isset($_POST['email'])){ - Viher