如何在新页面加载后提交 CFform 并更改其操作属性

how to submit a CFform and change its action attribute after the new page load?

本文关键字:属性 操作 CFform 提交 新页面 加载      更新时间:2023-09-26

我正在尝试使用cfform,用户可以在不同的网站上输入和搜索一些结果,这需要登录才能访问所需的结果。另一个网站将在弹出或新页面中打开,其中用户凭据已登录,并将显示用户之前在 cfform 或其他 cfform 或表单中输入的结果,我不确定应该如何完成。基本上,我想提供一种快速的方法,在与我的网站不同的网站中搜索结果,同时跳过包含结果的网站的用户的登录进度。

到目前为止,我有一个有效的 cfform,可以在用户已经登录的情况下打开 www.somewebsite.com,如下所示

<cfform action="https://www.somewebsite.com/login.php" method="post" id="ud_form">
     <cfinput type="hidden" name="email" value="#email#" />   
     <cfinput type="hidden" name="password" value="#password#" />
     <cfinput type="hidden" name="source" value="#source#"  />
</cfform>
<script type="text/javascript">
     document.getElementById('ud_form').submit();
</script>

遇到的问题是,登录过程完成后,我还没有找到更改操作属性的方法。例如,登录后,cfform 操作属性应设置为新 url + cfform 的输入值 (https://www.somewebsite.com/cp.php?addr="+form_address+"&unit="+form_unit),然后提交。我做了大量的研究,但找不到解决方案。

我尝试在上面的 cfform 中包含 cfinput 标签,并使用一个 javascript 函数,该函数将在提交表单后触发操作属性更改。但是,按下提交按钮无法触发任何操作,而不会在控制台中报告任何脚本错误。我使用的代码如下所示。

<cfform action="https://www.somewebsite.com/login.php" method="post" id="ud_form" onSuccess="show_results();">
        <cfinput type="hidden" name="email" value="#email#" />
        <cfinput type="hidden" name="password" value="#password#" />  
        <cfinput type="hidden" name="source" value="#source#"  />
        Address: <input id="address" type="Text" name="address" placeholder="Enter an Address" size=40><br/><br/>
        Unit #: <input id="unit" type="Text" name="unit" placeholder="Enter Unit" size=40><br/><br/>
        <input id="submit" type="button" value="Search">       
</cfform>

<script type="text/javascript">
       $("#submit").click(function(){                                                    
              $("#ud_form").submit();
       });
       function show_results()
       {
              var form_address =$("#address").val();
              form_address = form_address.split(' ').join('+');
              var form_unit = $("#unit").val();
              form_unit =form_unit.split(' ').join('+');
              var url = "https://www.somewebsite.com/cp.php?addr="+form_address+"&unit="+form_unit;                                               
              $('#ud_form').attr('action',url);                                                                          
              $("#ud_form").submit();
       }

任何帮助或建议将不胜感激!

一旦你提交了这个HTML表单,在这种情况下,浏览器就会离开你的代码 - 它将开始与 somewebsite.com 交互

我认为您要做的是将表单提交给自己并获取表单字段并用它们进行 CFHTTP www.somewebsite.com,然后使用返回的结果使用您刚刚获取的数据填充页面/对话框/弹出窗口。

否则,您只需将用户发送到该辅助站点,然后将其从您的站点导航出去。