Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

html - 链接以自动填充另一页中的输入框(Link to autofill an input box in another page)

I'm trying to create a link that when clicked on will redirect me to another html page with a contact form, and in that form there is a subject input box.

(我正在尝试创建一个链接,单击该链接会将我重定向到带有联系表单的另一个html页面,并且在该表单中有一个主题输入框。)

Depending on which link is clicked, I want the subject box to be populated with the corresponding link title.

(根据要单击的链接,我希望在主题框中填充相应的链接标题。)

Tried searching for awhile now and have no idea how to get it to work.

(尝试搜索了一段时间,却不知道如何使其工作。)

Tried playing around with the key value pairs method mentioned in some other places but definitely doing it wrong, and not sure how.

(尝试使用其他地方提到的键值对方法,但肯定做错了,不确定如何做。)

Below is a snippet of my code.

(以下是我的代码片段。)

The h3 "Title of the product here" is what I want to populate the subject box with (in my actual website I will have multiple links populating the subject lines with different words).

(h3“此处的产品标题”是我要填充主题框的内容(在我的实际网站中,我将有多个链接,用不同的单词填充主题行)。)

Main Page

(主页)

<div class="squareIndexContentBox1" style="background-color: #fff">
    <a href="contact us.html?subject=testing">
        <h3>Title of the product here</h3>
        <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        </p>
        <div class="learn-more">
            <span id="learn-more">Contact us</span>
            <span class="fa fa-hand-o-left"></span>
        </div>
    </a>
</div>

Page where I want the input box to be filled

(我要填写输入框的页面)

<div class="contact-form">
    <h2> Contact Us </h2>

    <form method="POST" action="contact-form-handler.php">
        <input type="text" name="name" placeholder="Name" required>
        <br>

        <input type="email" name="email" placeholder="Email" required>
        <br>

        <input id="subject" type="text" name="subject" placeholder="Subject" required>
        <br>

        <textarea type="text" name="message" placeholder="Message"></textarea>
        <br>

        <div class="g-recaptcha" data-sitekey=""></div>
        <br>

        <input type="submit" name="submit" class="submit-btn" value="Send Message">
    </form>
</div>

Thanks in advance!

(提前致谢!)

  ask by John Felix translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It depends how you navigate from main page to second page.

(这取决于您如何从主页导航到第二页。)

If you are using simple button to navigate to another page then pass the unique field name with button in url them use $_GET to get that variable and search specific fields in database with the help of that unique field and fill you inputs.

(如果您使用简单的按钮导航到另一个页面,然后在URL中使用带有按钮的唯一字段名称进行传递,则可以使用$ _GET获取该变量,并在该唯一字段的帮助下搜索数据库中的特定字段并填写您的输入。)

Secondly if you are navigating from main page to another page by clicking a submit button ie after filling some form then you can pass you unique field name by adding input type hidden to another page.

(其次,如果要通过单击提交按钮从主页导航到另一页,即填写某种表格后,则可以通过向另一页添加隐藏的输入类型来传递唯一的字段名称 。)

Example

(例)

First Example:  <a href="second_page.php?prop_id=5 ">Click </a>

Get this variable(prop_id) in second_page with the help of $_GET

(在$ _GET的帮助下,在second_page中获取此变量(prop_id))

Second Example: <input type="hidden" name="email_address" value="<?php echo $email_address;?>" >

Now by submitting the form this input type also send to other page.

(现在,通过提交表单,此输入类型也将发送到其他页面。)

Or you can pass that unique field to another page by using session .

(或者,您可以使用session将该唯一字段传递给另一个页面。)

* Unique Field name is the key through which you can easily find values from database.

(*唯一字段名称是您可以轻松从数据库中查找值的键。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...