【问题标题】:Contact form with image as buttons以图像为按钮的联系表格
【发布时间】:2014-01-04 07:15:53
【问题描述】:

如何使按钮的图像完好无损,并且仍然可以发送邮件或清除表单? 我正在尝试将图像用作此联系表单中的按钮。一个按钮是清除表单,另一个按钮是发送邮件到一个邮件ID。

我的php编码是:

<?php
$submitted = FALSE;
if ($_POST['contact_form']) {
    $submitted = TRUE;  // The form has been submitted and everything is ok so far…
    $name = htmlspecialchars($_POST['name'], ENT_QUOTES);
    $email = htmlspecialchars($_POST['email'], ENT_QUOTES);
    $website = htmlspecialchars($_POST['website'], ENT_QUOTES);
    $message = htmlspecialchars($_POST['message'], ENT_QUOTES);
    if ($name == "") {
        // if the name is blank… give error notice.
        echo "<p>Please enter your name.</p>";
        $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
    }
    if ($email == "") {
        // if the email is blank… give error notice.
        echo "<p>Please enter your e-mail address so that we can reply to you.</p>";
        $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
    }
    if ($message == "") {
        // if the message is blank… give error notice.
        echo "<p>Please enter a message.</p>";
        $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
    }
    if ($_POST['email'] != "" && (!strstr($_POST['email'], "@") || !strstr($_POST['email'], "."))) {
        // if the string does not contain "@" OR the string does not contain "." then…
        // supply a different error notice.
        echo "<p>Please enter a valid e-mail address.</p>";
        $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
    }
    $to = "genxcoders@gmail.com";  // Set the target email address.
    $header = "From: $email";
    $attention = "$name has sent you contact e-mail from GenXCoders.in Contact Form!";
    $message = "Attention: $attention \n From: $name \n Message: $message \n";
    if ($submitted == TRUE) {
        mail($to, $attention, $message, $header);
        echo "<p>Thank you $name. Your message has been sent.</p>";
    }
}
?>

我的 HTML 代码是:

<form id="form" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>">
    <fieldset>
        <p>
            <label>
                <input name="name" value="Name" onBlur="if (this.value == '')
                            this.value = 'Name'" onFocus="if (this.value == 'Name')
                                        this.value = ''"/>
            </label>
        </p>
        <p>
            <label>
                <input name="email" value="Email" onBlur="if (this.value == '')
                            this.value = 'Email'" onFocus="if (this.value == 'Email')
                                        this.value = ''" />
            </label>
        </p>
        <p>
            <label>
                <input name="website" value="Website" onBlur="if (this.value == '')
                            this.value = 'Name'" onFocus="if (this.value == 'Name')
                                        this.value = ''"/>
            </label>
        </p>
        <p>
            <label>
                <textarea name="message" cols="30" rows="20" onBlur="if (this.value == '') {
                            this.value = 'Message'
                        }" onFocus="if (this.value == 'Message') {
                                    this.value = ''
                                }" ></textarea>
            </label>
        </p>
        <div class="btns">
            <a href="" class="button">
                Clear
            </a>
            <a href="#" class="button" onClick="document.getElementById('form').submit()">
                Send
            </a>
        </div>  
    </fieldset>
</form>

【问题讨论】:

    标签: php html css imagebutton


    【解决方案1】:

    您可以通过添加另一个类将图像用作.button 类的background,或者您可以使用a 标记包装图像。

    例如: HTML

        <a href="#" class="button btn-send" onClick="document.getElementById('form').submit()">
        </a>
    

    CSS

    .btn-send {
      width:40px; /* width of the image or button */
      height:20px; /* height of the image or button */
      background-image: url('path-to-image') no-repeat top left;
      }
    

       <a href="#" class="button" onClick="document.getElementById('form').submit()">
         <img src="/path-to-image" alt="Send" />
                </a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-26
      • 2017-09-05
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 2016-02-21
      相关资源
      最近更新 更多