【问题标题】:Submit button is not working eveb if I have entered input data inside form [duplicate]即使我在表单中输入了输入数据,提交按钮也不起作用[重复]
【发布时间】:2020-10-16 02:57:58
【问题描述】:

我正在尝试从 whois 服务器请求数据并将其显示在我的页面上。如果我按 Enter 但提交按钮不起作用,它可以正常工作。

页面的url:

../whois.php

点击提交后我想要的网址

../whois.php?domain=somewebsite.com

这是我的 HTML 代码。

<section class="calltoaction section_sapce cover-image" data-image-src="images/subbanners/4.jpg">
    <div class="row">
        <div class="container">
            <div class="row cta-content">
                <div class="offerdescription">
                    <form action="<?=$_SERVER['PHP_SELF'];?>">
                        <b><label for="domain">
                            <h2 class="text-uppercase text-center">Domain/IP Address:</h2>
                            <p class=" text-center">Free WhoIs Lookup for any domain/IP. It's free and easy.</p>
                            </label>
                        </b>    
                        <div>
                            <form class="form-inline domainsearch">
                                <div class="row searchdomain">
                                    <div class="col-sm-6" style="margin-top:10px; margin-bottom: 10px; padding-right:0; padding-left:0;">
                                        <input class="form-control" type="text" name="domain" id="domain" placeholder="Enter Your Domain/IP" value="<?=$domain;?>" required onFocus="if (this.value == 'Enter your domain/IP') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Enter your domain/IP';}" value="Enter your domain/IP" > 
                                    </div>  
                                    <div class="col-sm-2" style="margin-top:10px; margin-bottom: 10px; padding-right:0; padding-left:0">    
                                        <button class="btn btn-new btn-lg" style="width:100%" type="button" action="<?=$_SERVER['PHP_SELF']."?".$domain;?>" name="button">Lookup</button>
                                    </div>
                                </div>
                            </form>
                        </div>  
                    </form> 
                </div>
            </div>  
        </div>      
    </div>
</section>

你能帮我解决一下吗?

【问题讨论】:

    标签: php html css forms


    【解决方案1】:

    您可以使用按钮 type="submit" 代替 type="button" 像这样

    <button class="btn btn-new btn-lg" style="width:100%" type="submit" action="<?=$_SERVER['PHP_SELF']."?".$domain;?>" name="button">Lookup</button>
    

    【讨论】:

    • 我应该将操作留空吗?
    • 您不需要对button 执行任何操作(实际上它什么也不做)。该操作仅对form 有意义。如果需要,您可以在此处添加 action="" 以使其明确。 domain 参数将作为查询参数发送,因为这是通过 GET(这是默认方法)发送时表单处理其值的方式。
    【解决方案2】:

    按钮需要有一个类型提交

    【讨论】:

      【解决方案3】:

      尝试在表单中而不是在按钮中定义操作,并将按钮的类型从按钮更改为提交

      【讨论】:

      • 该操作不是必需的,因为默认操作是一个由空字符串组成的相对 URL,这基本上是当前 URL,并且输入已经作为查询参数发送。
      猜你喜欢
      • 2017-03-07
      • 2016-03-14
      • 2021-01-08
      • 1970-01-01
      • 2021-11-23
      • 2018-10-29
      • 1970-01-01
      • 2011-03-23
      • 2015-11-08
      相关资源
      最近更新 更多