【发布时间】:2017-09-03 02:49:39
【问题描述】:
我正在尝试在同一页面上创建一些随机词生成器来生成动词、名词等(最终创建一个情节生成器,但用户可以选择随机生成的建议)
我已经成功创建了它,但是,当我单击同一页面上的另一个生成器时,我希望生成的随机词留在框中(例如,如果我单击建议一个名词并生成一个词,那么我去点击建议一个形容词和一个形容词生成,但名词从前一个框中消失)
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<?php
{
{
$Noun=array("just", "assume", "there", "are", "lots", "of", "nouns", "in", "here");
//echo rand(0, 2);
$myRandom = rand(0, 99);
//echo $Cars[$myRandom];
//if first name is blank/null then put
}
?>
<form action="quote.php">
Noun<br>
<input type="text" name="firstname"
value="<?php if (isset($_GET['Noun'])){echo $Noun[$myRandom];} }?>"><br>
<input type="submit" name ="Noun" value="Suggest">
</form>
<?php
{
{
$Adj=array("just", "assume", "there", "are", "lots", "of", "adjectives", "in", "here");
//echo rand(0, 2);
$Random = rand(0, 99);
//echo $Cars[$myRandom];
//if first name is blank/null then put
}
?>
<form action="quote.php">
Noun<br>
<input type="text" name="firstname"
value="<?php if (isset($_GET['Adjective'])){echo $Adj[$Random];} }?>"><br>
<input type="submit" name ="Adjective" value="Suggest">
</form>
</body>
</html>
【问题讨论】:
-
您的表单中没有方法。您打算使用
POST或GET吗? -
我不太确定,我对此很陌生,我很抱歉。基本上我试图在这个网站上重新创建类似的东西plot-generator.org.uk/story - 我想可能是
POST的建议按钮,因为我只是希望代码出现在框内 - 而不是提交新表单?? -
嘿@Gareth,在我给出答案之前,我只想知道。 quote.php 是否会以一些结果重定向回此页面?
-
嗨@Douglas-我是的,我认为确实如此-我可能做错了-我正处于尝试构建类似于此网站的过程的开始-plot-generator.org.uk/story - 目前我只是想在继续之前开发建议按钮