/ / PHP echo variable de entrada HTML fuera de heredoc - javascript, php, html

Variable de entrada PHP echo HTML fuera de heredoc - javascript, php, html

Incluyo mi HTML en PHP usando heredoc, ydesea obtener la variable de entrada del usuario que está dentro de heredoc y hacer eco de ella. Intenté usar $ _GET ["input"], pero obtuve el error índice indefinido: input ¿Puedo saber cómo obtener la variable de entrada?

<?php
$htmlfile= <<<html
<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8">
<title>Seller Evaluation System</title>
<style type="text/css">
body {background-image:url("images.jpg");}
</style>
</head>

<body>
<h1><center><font color="darkblue">Seller Evaluation System</font><center></h1>

<p><center>
<script>
function searchSite(){
var input=document.getElementById("searchinput").value;
var searchForm=document.getElementById("searchForm");
searchForm.action="http://www.mudah.my/Malaysia/Electronics-3000/"+input+"-for-sale?lst=0&fs=1&q="+input+"y&cg=3000&w=3&so=1&st=s";
searchForm.submit();
}
</script>

<form method="get" action="ttt.php" id="searchForm">
<input type="text" id="searchinput" size="33" placeholder="Search Electronic Gadgets..." autofocus>
<button onclick="searchSite()">Search</button>
</form>

<p><label>Mudah<input type="checkbox" name="searchFrom" value="Mudah" checked/></label>
<label><font color="grey">Lazada</font><input type="checkbox" name="searchFrom" value="Lazada" disabled="disabled"/></label>
<label><font color="grey">Lelong</font><input type="checkbox" name="searchFrom" value="Lelong" disabled="disabled"/></label>
<label><font color="grey">Ebay</font><input type="checkbox" name="searchFrom" value="Ebay" disabled="disabled"/></label></p>
</center></p></br>
</body>
</html>
html;

echo $htmlfile;

$userInput=$_GET["input"];
echo $userInput;
?>

Respuestas

0 para la respuesta № 1

Debe llamar al nombre de entrada "searchinput". Pero no podría estar disponible si no envía el formulario, y debe llamarlo por la etiqueta "nombre", no por "id".

Puede mostrarlo después de enviarlo usando Javascript, no PHP.

Esto funciona, pero el formulario debe ser procesado por el mismo archivo, por lo que la "acción" debe estar vacía. De lo contrario, puede obtener los parámetros GET en el proceso de archivo de su formulario, en su ejemplo ttt.php

<?php
$htmlfile= <<<html
<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8">
<title>Seller Evaluation System</title>
<style type="text/css">
body {background-image:url("images.jpg");}
</style>
</head>

<body>
<h1><center><font color="darkblue">Seller Evaluation System</font><center></h1>

<p><center>



<form method="get"  id="searchForm">
<input type="text" name="searchinput" size="33" placeholder="Search Electronic Gadgets..." autofocus>
<button type="submit">Search</button>
</form>


</center></p></br>
</body>
</html>
html;

echo $htmlfile;

$userInput=$_GET["searchinput"];
echo $userInput;
?>

0 para la respuesta № 2

$_GET[..] toma el nombre de un elemento de formulario. Entonces en tu HTML necesitas incluir eso:

<input type="text" name="input" id="searchinput" size="33" placeholder="Search Electronic Gadgets..." autofocus>

También tenga en cuenta que solo desea obtener el artículo cuando envió el formulario, primero debe verificar que GET existe:

// If we submitted our form with a element named "input", then echo
if(isset($_GET["input"]) {
$userInput=$_GET["input"];
echo $userInput;
}

De esa manera, el código solo se ejecutará si se envió el formulario.