简体   繁体   English

使用表单字段中的数据填充动态链接

[英]Populate Dynamic Link With Data From Form Fields

I've been working for a bit of time on this project and would appreciate any help. 我已经在这个项目上工作了一段时间,希望能对您有所帮助。 I have a form and would like the data from the form used in a PHP file that I've written that uses $_GET to pull those values and then use them in the PDF. 我有一个表单,想要从我编写的PHP文件中使用的表单中的数据,该文件使用$ _GET提取这些值,然后在PDF中使用它们。

With some help, I've been able to come up with a script that uses the blur function to retrieve the data from the form and insert it into a dynamic link which then passes the values to the PHP file and have constructed a working jFiddle here: 在一些帮助下,我已经能够提出一个脚本,该脚本使用blur函数从表单中检索数据并将其插入到动态链接中,然后将值传递给PHP文件并在此处构造了一个有效的jFiddle :

http://jsfiddle.net/ZhCZS/3/ http://jsfiddle.net/ZhCZS/3/

Form code: 表单代码:

<form class="cart" method="post" enctype='multipart/form-data'>
<div class="gform_variation_wrapper gform_wrapper">
    <input type="hidden" id="product_id" name="product_id" value="36" />
    <input type="hidden" id="_wpnonce" name="_wpnonce" value="4ededc9481" />
    <input type="hidden" name="_wp_http_referer" value="/product/prepare-for-your-closing-copy/" />
    <div class='gf_browser_gecko gform_wrapper' id='gform_wrapper_1'>
        <div class='gform_body'>
            <ul id='gform_fields_1' class='gform_fields top_label description_below'>
                <li id='field_1_13' class='gfield           gfield_price gfield_price_1_13 gfield_product_1_13    gfield_contains_required'>
                    <label class='gfield_label' for='input_1_13'>Quantity<span class='gfield_required'>*</span>
                    </label>
                    <div class='ginput_container'>
                        <select name='input_13' id='input_1_13' class='medium gfield_select' tabindex='1'>
                            <option value='500 - $269.00|269'>500 - $269.00</option>
                            <option value='1000 - $319.00|319'>1000 - $319.00</option>
                        </select>
                    </div>
                </li>
                <li id='field_1_14' class='gfield'>
                    <label class='gfield_label' for='input_1_14'>Total</label>
                    <div class='ginput_container'><span class='ginput_total ginput_total_1'>$0.00</span>
                        <input type='hidden' name='input_14' id='input_1_14' class='gform_hidden' />
                    </div>
                </li>
                <li id='field_1_1' class='gfield'>
                    <label class='gfield_label' for='input_1_1'>Location</label>
                    <div class='ginput_container'>
                        <select name='input_1' id='input_1_1' class='medium gfield_select' tabindex='2'>
                            <option value='Addison'>Addison</option>
                            <option value='Arlington'>Arlington</option>
                            <option value='Colleyville'>Colleyville</option>
                            <option value='Fire Wheel'>Fire Wheel</option>
                            <option value='Flower Mound'>Flower Mound</option>
                            <option value='Fort Worth'>Fort Worth</option>
                            <option value='Legacy'>Legacy</option>
                            <option value='Mansfield'>Mansfield</option>
                            <option value='McDermott'>McDermott</option>
                            <option value='Preston Corners'>Preston Corners</option>
                        </select>
                    </div>
                </li>
                <li id='field_1_19' class='gfield'>
                    <label class='gfield_label' for='input_1_19'>Address</label>
                    <div class='ginput_container'>
                        <input name='input_19' id='input_1_19' type='text' value='' class='medium' tabindex='3' />
                    </div>
                </li>
                <li id='field_1_21' class='gfield'>
                    <label class='gfield_label' for='input_1_21'>City, State, ZIP</label>
                    <div class='ginput_container'>
                        <input name='input_21' id='input_1_21' type='text' value='' class='medium' tabindex='4' />
                    </div>
                </li>
                <li id='field_1_20' class='gfield'>
                    <label class='gfield_label' for='input_1_20'>Suite1</label>
                    <div class='ginput_container'>
                        <input name='input_20' id='input_1_20' type='text' value='' class='medium' tabindex='5' />
                    </div>
                </li>
                <li id='field_1_11' class='gfield'>
                    <label class='gfield_label' for='input_1_11'>Reference</label>
                    <div class='ginput_container'>
                        <input name='input_11' id='input_1_11' type='text' value='' class='medium' tabindex='6' />
                    </div>
                </li>
                <li id='field_1_12' class='gfield'>
                    <label class='gfield_label' for='input_1_12'>Notes</label>
                    <div class='ginput_container'>
                        <textarea name='input_12' id='input_1_12' class='textarea medium' tabindex='7' rows='10' cols='50'></textarea>
                    </div>
                </li>
                <li id='field_1_15' class='gfield     gform_hidden'>
                    <input name='input_15' id='input_1_15' type='hidden' class='gform_hidden' value='Vendor X' />
                </li>



<li id='field_1_22' class='gfield      gfield_html gfield_html_formatted gfield_no_follows_desc'>
<a id="mylink" href="#" target="_blank">Send to PDF</a>

<span>the link contains: </span><span id="showmehref"></span>
                </li>
            </ul>
        </div>
        <div class='gform_footer top_label'>
            <input type='hidden' class='gform_hidden' name='is_submit_1' value='1' />
            <input type='hidden' class='gform_hidden' name='gform_old_submit' value='1' />
            <input type='hidden' class='gform_hidden' name='gform_unique_id' value='' />
            <input type='hidden' class='gform_hidden' name='state_1' value='WyJhOjE6e2k6MTM7YToyOntpOjA7czozMjpcIjYzNDM5OTkzYmRhMDU2NGM5NWUwNGU4ZDgyNTM4NWFiXCI7aToxO3M6MzI6XCI1MTk1MjNiNmI1ZDM0NDk2NmJhZGY3M2I4YzIxYWEyYlwiO319IiwiMTYzYjgzMmJjODZhMWU2NzJkYTQ5YTQ3OWE2OWJjMzciXQ==' />
            <input type='hidden' class='gform_hidden' name='gform_target_page_number_1' id='gform_target_page_number_1' value='0' />
            <input type='hidden' class='gform_hidden' name='gform_source_page_number_1' id='gform_source_page_number_1' value='1' />
            <input type='hidden' name='gform_field_values' value='' />
        </div>
    </div>
    <input type="hidden" name="gform_form_id" id="gform_form_id" value="1" />
    <input type="hidden" id="woocommerce_get_action" value="" />
    <input type="hidden" id="woocommerce_product_base_price" value="0" />
</div>
<input type="hidden" name="add-to-cart" value="36" />
<div class="clear"></div>
<div class="quantity">
    <input type="number" step="1" min="1" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" />
</div>
<input type="hidden" name="add-to-cart" value="36" />
<button type="submit" class="addToCart single_add_to_cart_button button alt">Add to cart</button>
</form>

Script code: 脚本代码:

$("form.cart").on('blur', ':input', function(){
var linkText = "http://www.ortorderdesk.com/proofs/397288.php?" + $("form.cart").serialize();
$("#showmehref").text(linkText);
$("#mylink").attr('href', linkText);
});

Unfortunately, when I implement the code into my site, it doesn't work. 不幸的是,当我在自己的站点中实现代码时,它不起作用。 It simply appends the URL of the current page with "#", essentially ignoring the script. 它只是在当前页面的URL后面加上“#”,实际上忽略了脚本。

Please see the code in use at: http://www.ortorderdesk.com/product/prepare-for-your-closing-copy/ 请在以下位置查看使用的代码: http : //www.ortorderdesk.com/product/prepare-for-your-closing-copy/

The javascript file containing my script is called blur.js. 包含我的脚本的javascript文件称为blur.js。

Am I not calling it properly? 我打的不好吗? Is there an error in my syntax implementing it into my site? 在将其实施到我的网站时,我的语法有错误吗?

I've tried referencing blur.js in the header and footer with no positive results. 我尝试在页眉和页脚中引用blur.js,但没有任何积极结果。

Any help is great appreciated. 任何帮助都非常感谢。

Thanks! 谢谢!

Is the Script Part in script Block. 是脚本块中的脚本部分。 if OK you Script must have a $(document).ready(function(){.....}. is necessary, does the code runs after the Site is loaded. 如果可以,则脚本必须具有$(document).ready(function(){.....}。),在加载站点后是否运行代码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM