Javascript PHP联系人表单正在打开一个新的浏览器选项卡

Javascript PHP联系人表单正在打开一个新的浏览器选项卡,javascript,php,Javascript,Php,我需要另一双眼睛来观察这个。我不明白为什么点击webform_contact.php上的提交按钮会启动第二个选项卡。在某一点上,提交表单并重新加载当前选项卡可以正常工作。第二天早上,我打开了这个项目,没有做任何代码更改,它又在submit上打开了一个新选项卡。我觉得我快疯了 index.php <a href="javascript:void(0);" class="btn btn-mob-full btn-lg btn btn-blue trigger-show-modal-ask" t

我需要另一双眼睛来观察这个。我不明白为什么点击webform_contact.php上的提交按钮会启动第二个选项卡。在某一点上,提交表单并重新加载当前选项卡可以正常工作。第二天早上,我打开了这个项目,没有做任何代码更改,它又在submit上打开了一个新选项卡。我觉得我快疯了

index.php

<a href="javascript:void(0);" class="btn btn-mob-full btn-lg btn btn-blue trigger-show-modal-ask" title="Ask a Question">Ask a Question</a>
webform_contact_process.php

<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

$from = 'noreply@someemail.com';
$sendTo = 'youremail@someemail.com';
$subject = 'Web Request. Ask a Question: -  ' .$_POST['z_subject'] .' by ' .$_POST['z_firstname'];
$okMessage = 'Contact form successfully submitted. Thank you, We will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';

// let's do the sending
try
{


    $title = "New request for - " .$_POST['z_subject'] ."\n";

    $htmlContent = '
    <table cellspacing="0" style="font-family: OpenSans-Regular; border-collapse: collapse; background: white; border-radius: 10px; overflow: hidden; width: 60%; margin: 0 auto; position: relative;">
    <thead> <tr style="height: 60px; background: #36304a; color: #fff;"><th colspan="7" style="font-family: OpenSans-Regular; font-size: 18px; color: #fff; line-height: 1.2; font-weight: unset;">' .$title . '</th></tr></thead>
        <tr style="height: 30px;font-family: OpenSans-Regular;font-size: 15px;color: #808080;line-height: 1.2;font-weight: unset;">
            <th style="width: 230px; padding: 20px; text-align: left;">Message:</th><td style="padding:20px;">' .$_POST['lead_description'] .'</td>
        </tr>        
    </table>';

    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $headers .= 'From:' . $from . "\r\n";

    mail($sendTo, $subject, $htmlContent, $headers);

    $responseArray = array('type' => 'success', 'message' => $okMessage);
    // redirect to index page
    header('Location: /index.php?message=asknowsent');
}
catch (\Exception $e)
{
    $responseArray = array('type' => 'danger', 'message' => $errorMessage);
}

if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    $encoded = json_encode($responseArray);

    header('Content-Type: application/json');

    echo $encoded;
}
else {
    echo $responseArray['message'];
}
webform_contact.php

    <!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
</head>

<body>

<div class="modal modal-ask mar-bot--0">
    <div class="modal-fade-screen mar-bot--0">
        <div class="modal-inner">
            <div class="modal-close modal-ask"></div>
            <i class="icon-email-0 xl float-l pad-vert--2 mar-right--1"></i>
            <h4 class="color--blue">Have a Question?</h4>
            <p style="margin-left: 78px;">Display a Message Here</p>
            <div class='gf_browser_chrome gform_wrapper' id='gform_wrapper_2'>
                <form id='contact-lo-form' method='post' target='gform_ajax_frame_1' action='/include/webform_contact_process.php' role='form'>
                    <div class='gform_heading'>
                        <span class='gform_description'></span>
                    </div>

                    <div class="messages"></div>

                    <div class='gform_body'>
                        <ul id='gform_fields_2' class='gform_fields top_label form_sublabel_below description_below'>

                            <li id='form_firstname' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_firstname'>First Name<span class='gfield_required'>*</span></label>
                                <div class='ginput_container ginput_container_text'>
                                    <input name='z_firstname' id='form_firstname' type='text' value='' class='large' tabindex='400' placeholder='First Name' required='required' data-error='First Name is required.' />
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>

                            <li id='form_lastname' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_lastname'>Last Name<span class='gfield_required'>*</span></label>
                                <div class='ginput_container ginput_container_text'>
                                    <input name='z_lastname' id='form_lastname' type='text' value='' class='large' tabindex='401' placeholder='Last Name' required='required' data-error='Last Name is required.' />
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>

                            <li id='form_email' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_email'>Email Address<span class='gfield_required'>*</span></label>
                                <div class='ginput_container ginput_container_text'>
                                    <input name='z_requester' id='form_email' type='email' value='' class='large' tabindex='402' placeholder='Email Address' required='required' data-error='Valid email is required.' />
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>

                            <li id='form_phone' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_phone'>Phone Number<span class='gfield_required'>*</span></label>
                                <div class='ginput_container ginput_container_text'>
                                    <input name='z_phone' id='form_phone' type='text' value='' class='large' tabindex='403' placeholder='Phone Number' required='required' data-error='Phone number is required.' />
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>

                            <li id='form_zipcode' class='gfield gfield_contains_required field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_zipcode'>Zip Code<span class='gfield_required'>*</span></label>
                                <div class='ginput_container ginput_container_text'>
                                    <input name='z_zipcode' id='form_zipcode' type='text' value='' class='large' tabindex='404' placeholder='Zip Code' required='required' data-error='Zip code is required.' />
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>

                            <li id='form_description' class='gfield field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_description'>Question</label>
                                <div class='ginput_container ginput_container_textarea'>
                                    <textarea name='lead_description' id='form_description' class='textarea large' tabindex='405' placeholder='Enter your question...' rows='10' cols='50' required='required' data-error='Enter question is required.'></textarea>
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>

                            <li id='form_howtohearus' class='gfield full-field field_sublabel_below field_description_below'>
                                <label class='gfield_label' for='form_howtohearus'>How Did You Hear About Us?</label>
                                <div class='ginput_container ginput_container_select'>
                                    <select name='z_howtohearus' id='form_howtohearus' onchange='gf_apply_rules(1,[5]);' class='medium gfield_select' tabindex='505' required='required' data-error='Please,select one option.'>
                                        <option value='' selected='selected' class='gf_placeholder'>How Did You Hear About Us?</option>
                                        <option value='Facebook'>Facebook</option>
                                        <option value='Twitter'>Twitter</option>
                                        <option value='LinkedIn'>LinkedIn</option>
                                        <option value='Other Website'>Other Website</option>
                                        <option value='Friend/Family Referral'>Friend/Family Referral</option>
                                        <option value='Community Event'>Community Event</option>
                                        <option value='Other'>Other</option>
                                    </select>
                                    <div class="help-block with-errors"></div>
                                </div>
                            </li>
                            <li id='form_subject' class='gfield gform_hidden field_sublabel_below field_description_below'>
                                <input name='z_subject' id='form_subject' type='hidden' class='gform_hidden' value='Contact Form ' />
                            </li>
                        </ul>
                    </div>
                    <div class="col-md-12 gform_footer top_label">
                        <input type="submit" class="btn btn-success btn-send gform_button" value="Send Message">
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>

</body>

</html>
您已在您的上定义了属性:

<form id='contact-lo-form' method='post' target='gform_ajax_frame_1' action='/include/webform_contact_process.php' role='form'>

就这样。这是我在试图让它在iframe中工作时留下的一个工件。谢谢你,狼
target='gform_ajax_frame_1'