【问题标题】:Run PHP script and also submit form to URL运行 PHP 脚本并将表单提交到 URL
【发布时间】:2017-06-29 05:44:38
【问题描述】:

我有一个 HTML 注册表单,它使用 PHP 将用户添加到内容管理系统。我需要将此集成到我的客户关系管理工具 (AgileCRM) 中。

此代码将允许用户注册,这将提交表单并使用 PHP 创建用户。

<?php
if ($input->post->submit) {
  //create user
}
?>
<form action='./' accept-charset='UTF-8' autocomplete='off' method='post'>
    <input type='text' name='username' placeholder='Username'>
    <input type='text' name='email' placeholder='Email'>
    <input type='password' name='password' placeholder='Password'>
    <button type='submit' name='submit' value='register'>Register</button>
</form>

然后这段代码将在 CRM 中执行我想要的操作

<link href="https://s3.amazonaws.com/agilecrm/forms/v1/agile-form-min.css" rel="stylesheet">
<form class="form-view  " id="agile-form" action="https://agiledomain.agilecrm.com/formsubmit" style="max-width:450px;" method="post">
<fieldset>

<!-- Form Name -->
<legend class="agile-hide-formname">Registration Form</legend>
<p class="agile-form-description"></p>
<div style="display: none; height: 0px; width: 0px;">
<input type="hidden" id="_agile_form_name" name="_agile_form_name" value="Registration Form">
<input type="hidden" id="_agile_domain" name="_agile_domain" value="AGILECRMDOMAIN">
<input type="hidden" id="_agile_api" name="_agile_api" value="AGILECRMAPIKEY">
<input type="hidden" id="_agile_redirect_url" name="_agile_redirect_url" value="#">
<input type="hidden" id="_agile_document_url" name="_agile_document_url" value="">
<input type="hidden" id="_agile_confirmation_msg" name="_agile_confirmation_msg" value="Thank you for signing up!">
<input type="hidden" id="_agile_form_id_tags" name="tags" value="">

<input type="hidden" id="_agile_form_id" name="_agile_form_id" value="AGILECRMID">
</div>
<!-- Text input-->
<div class="agile-group required-control">
  <label class="agile-label" for="username">Username<span class="agile-span-asterisk"> *</span></label>
  <div class="agile-field-xlarge agile-field">
    <input maxlength="250" id="username" name="Username" type="text" placeholder="" class="agile-height-default" required="">
  </div>
  <div class="agile-custom-clear"></div>
</div>
<!-- Text input-->
<div class="agile-group required-control">
  <label class="agile-label" for="email">Email<span class="agile-span-asterisk"> *</span></label>
  <div class="agile-field-xlarge agile-field">
    <input maxlength="250" id="email" name="email" type="email" placeholder="" class="agile-height-default" required="">
  </div>
  <div class="agile-custom-clear"></div>
</div>
<!-- Password input-->
<div class="agile-group required-control">
  <label class="agile-label" for="password">Password Input<span class="agile-span-asterisk"> *</span></label>
  <div class="agile-field-xlarge agile-field">
    <input maxlength="250" id="password" name="password" type="password" placeholder="" class="agile-height-default" required="">
  </div>
  <div class="agile-custom-clear"></div>
</div>

<!--recaptcha aglignment-->
<!-- Button -->
<div class="agile-group">
  <label class="agile-label">&nbsp;</label>
  <div class="agile-field agile-button-field">
    <button type="submit" class="agile-button">Submit</button>
    <br><span id="agile-error-msg"></span>
  </div>
</div>

</fieldset>
</form>
<script type="text/javascript">
(function(a){var b=a.onload,p=true;isCaptcha=false;if(p){a.onload="function"!=typeof b?function(){try{_agile_load_form_fields()}catch(a){}}:function(){b();try{_agile_load_form_fields()}catch(a){}}};var formLen=document.forms.length;for(i=0;i<formLen;i++){if(document.forms.item(i).getAttribute("id")== "agile-form"){a.document.forms.item(i).onsubmit=function(a){a.preventDefault();try{_agile_synch_form_v5(this)}catch(b){this.submit()}}}}})(window);
</script>

所以基本上我想将这两个表单的功能结合在一起,所以将表单提交给 AgileCRM 并运行 PHP 代码。

【问题讨论】:

    标签: php html forms crm


    【解决方案1】:

    你可以用 jQuery ajax 做到这一点 并为您的第一个表单提供一个 id,然后它将在敏捷表单之后提交。

     $('#agile-form').submit(function(){
        // show that something is loading
        $('#response').html("<b>Loading response...</b>");
    
        /*
         * 'post_receiver.php' - where you will pass the form data
         * $(this).serialize() - to easily read form data
         * function(data){... - data contains the response from post_receiver.php
         */
        $.ajax({
            type  :'POST',
            url : "https://agiledomain.agilecrm.com/formsubmit", 
            async: false,
            data: $(this).serialize()
        })
        .done(function(data){ 
            //give your first form an id and submit it for eg:firsForm
         $('#firstForm').submit();
        })
        .fail(function() {
            // just in case posting your form failed
            alert( "Posting failed." );     
        });
        // to prevent refreshing the whole page page
        return false;
    });
    

    【讨论】:

    • 我对 jQuery/ajax 没有太多经验。我没有引用所有内容,您能否提供更多详细信息。这就是我目前得到的pastebin.com/r51aKMfE
    • 你得到了什么结果??
    • 我收到“发布失败”。
    猜你喜欢
    • 2014-08-23
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多