1

我想提交一个基于 ajax 响应的 PayPal 表单。问题是 ajax 部分工作正常,但仍然没有提交表单。

首先,我在表单中使用了一个按钮(而不是提交按钮)。在那个按钮上调用了一个 JavaScript 函数,如果 ajax 响应是肯定的,那么表单将被提交。

这是我的脚本

<script>
function mustvalid() {

    var company_name = document.forms["cord_form"]["company_name"].value;
    var slogan = document.forms["cord_form"]["slogan"].value;
    var cord_email = document.forms["cord_form"]["cord_email"].value;
    var company_do = document.forms["cord_form"]["company_do"].value;
    var brand_color = document.forms["cord_form"]["brand_color"].value;
    var imaginary = document.forms["cord_form"]["imaginary"].value;
    var ex_logo = document.forms["cord_form"]["ex_logo"].value;

    alert('hiidoooo');

    $.post("<?php echo base_url();?>ajax/set_custom_order", {
        'company_name': company_name,
            'slogan': slogan,
            'cord_email': cord_email,
            'company_do': company_do,
            'brand_color': brand_color,
            'imaginary': imaginary,
            'ex_logo': ex_logo
    },

    function (data) {
        if (data == "done") {
            alert(data);
            document.getElementById('cord_form').submit();
            // this line isnt working so the alert following this line is also not working;
            alert('hmm');
        } else {
            alert('hii');
        }
    });
}    
</script>

<div class="pitch single">
        <h1>Custom Order</h1>

    <!--<?php echo $cms[0]['content_desc']; ?>-->
</div>
<div id="top_adv">
    <?php echo $top_adv; ?>
</div>
<link href="<?php echo base_url(); ?>css/stylish-select.css" rel="stylesheet" type="text/css" media="all" />
<div class="content">
    <form name="cord_form" id="cord_form" method="post" action="abc.php">
        <div class="contact_us_form_space">
            <div>
                <input type="text" value="Name of Company" name="company_name" class="contact_name contact_input" />
            </div>
            <div>
                <input type="text" value="Slogan [If Any]" name="slogan" class="contact_email contact_input" />
            </div>
            <div>
                <input type="text" value="Email" name="cord_email" class="contact_email contact_input" />
            </div>
            <textarea class="contact_message" name="company_do" value="What does your company do?" onfocus="if(this.value == 'What does your company do?') { this.value = ''; }" onblur="if (this.value == '') { this.value='What does your company do?'; }">What does your company do?</textarea>
            <textarea class="contact_message" name="competitors" value="What sets you apart from competitors?" onfocus="if(this.value == 'What sets you apart from competitors?') { this.value = ''; }" onblur="if (this.value == '') { this.value='What sets you apart from competitors?'; }">What sets you apart from competitors?</textarea>
            <textarea class="contact_message" name="brand_color" value="What are your brand colors [If any]" onfocus="if(this.value == 'What are your brand colors [If any]') { this.value = ''; }" onblur="if (this.value == '') { this.value='What are your brand colors [If any]'; }">What are your brand colors [If any]</textarea>
            <textarea class="contact_message" name="imaginary" value="Do you have any specific imagery in mind?" onfocus="if(this.value == 'Do you have any specific imagery in mind?') { this.value = ''; }" onblur="if (this.value == '') { this.value='Do you have any specific imagery in mind?'; }">Do you have any specific imagery in mind?</textarea>
            <textarea class="contact_message" name="ex_logo" value="Examples of logos you like and why?" onfocus="if(this.value == 'Examples of logos you like and why?') { this.value = ''; }" onblur="if (this.value == '') { this.value='Examples of logos you like and why?'; }">Examples of logos you like and why?</textarea>
        </div>
        <img src="<?=site_url('home/securimage')?>" title="captcha" id="captcha2" />
        <input type="text" name="captcha_code" size="10" maxlength="6" />   <a href="#" onclick="document.getElementById('captcha2').src = '<?=site_url('home/securimage')?>?' + Math.random(); return false">[ Different Image ]</a>

        <br/>
        <?php echo @$_SESSION[ 'ctform'][ 'captcha_error'] ?>
        <br/>
        <input type="hidden" name="amount" value="$10">
        <input type="hidden" name="lc" value="US">
        <input type="button" value="Send" name="submit" class="contact_submit" onclick="mustvalid()" />
    </form>

我只是不知道这里有什么错误。

4

2 回答 2

0

您做得对,但有时名称冲突,因此更改 id 的名称并重试希望它会起作用:

$("#myform").submit();
document.getElementById('myform').submit();
document.myForm.submit(); 
于 2013-06-28T06:42:21.490 回答
0

尝试将按钮的名称更改为“提交”以外的名称。这可能会导致冲突。既然您使用的是 jQuery,为什么不将您的行更改为:

$("#cord_form").submit();
于 2013-06-28T05:47:15.590 回答