如何使用1个提交按钮执行2个操作?

时间:2013-10-09 13:39:59

标签: php html forms mailchimp

我正在尝试将数据提交到我的邮件黑猩猩列表中,但也允许用户上传文件。

这是我的代码,第一个块是mailchimp自动生成的表单,通过以下方式提交:

<div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>

然后是提交文件的基本代码。但目前这两个函数都有一个提交按钮。我只想要一个。有人可以帮忙吗?

<body>
    <!-- Begin MailChimp Signup Form -->
    <div id="mc_embed_signup">
        <form action="http://test.us7.list-manage.com/subscribe/post?u=d12b70d4bb1e08c1568d5b392&amp;id=bfb41cbf75" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
            <h2>Subscribe to our test mailing list</h2>
            <div class="indicates-required">
                <span class="asterisk">*</span> indicates required
            </div>
            <div class="mc-field-group">
                <label for="mce-EMAIL">
                    Email Address  <span class="asterisk">*</span>
                </label>
                <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
            </div>
            <div class="mc-field-group">
                <label for="mce-FNAME">First Name </label>
                <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
            </div>
            <div class="mc-field-group">
                <label for="mce-LNAME">Last Name </label>
                <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
            </div>
            <div class="mc-field-group input-group">
                <strong>Interests </strong>
                <ul>
                    <li><input type="checkbox" value="1" name="group[5597][1]" id="mce-group[5597]-5597-0"><label for="mce-group[5597]-5597-0">Interest 1</label></li>
                    <li><input type="checkbox" value="2" name="group[5597][2]" id="mce-group[5597]-5597-1">     <label for="mce-group[5597]-5597-1">Interest 2</label></li>
                    <li><input type="checkbox" value="4" name="group[5597][4]" id="mce-group[5597]-5597-2"><label for="mce-group[5597]-5597-2">Interest 3</label></li>
                </ul>
            </div>
            <div id="mce-responses" class="clear">
                <div class="response" id="mce-error-response" style="display:none"></div>
                <div class="response" id="mce-success-response" style="display:none"></div>
            </div>
        </div>
        <form action="upload_file.php" method="post" enctype="multipart/form-data">
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file"><br>
            <input type="submit" name="submit" value="Submit">
            <div class="clear">
                <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
            </div>
        </form>
    </form>
</body>

1 个答案:

答案 0 :(得分:0)

您可以通过upload_file.php文件路由MailChimp信息来实现此目的。

MailChimp有一个很棒的API,您不仅可以将订阅者添加到列表中。你会特别想要listSubscribe() function。该页面上有一些很好的例子。

以下是有关MailChimp API的更多文档:http://apidocs.mailchimp.com/api/2.0/

因此,在HTML中,您需要删除第二个提交按钮,并使用action =“upload_file.php”将其设置为一个表单。 PHP文件将上传文件,然后使用API​​将数据提交给MailChimp。

你的HTML应该是这样的:

<body>
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
    <form action="upload_file.php" method="post" enctype="multipart/form-data">
        <h2>Subscribe to our test mailing list</h2>
        <div class="indicates-required">
            <span class="asterisk">*</span> indicates required
        </div>
        <div class="mc-field-group">
            <label for="mce-EMAIL">
                Email Address  <span class="asterisk">*</span>
            </label>
            <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
        </div>
        <div class="mc-field-group">
            <label for="mce-FNAME">First Name </label>
            <input type="text" value="" name="FNAME" class="" id="mce-FNAME">
        </div>
        <div class="mc-field-group">
            <label for="mce-LNAME">Last Name </label>
            <input type="text" value="" name="LNAME" class="" id="mce-LNAME">
        </div>
        <div class="mc-field-group input-group">
            <strong>Interests </strong>
            <ul>
                <li><input type="checkbox" value="1" name="group[5597][1]" id="mce-group[5597]-5597-0"><label for="mce-group[5597]-5597-0">Interest 1</label></li>
                <li><input type="checkbox" value="2" name="group[5597][2]" id="mce-group[5597]-5597-1">     <label for="mce-group[5597]-5597-1">Interest 2</label></li>
                <li><input type="checkbox" value="4" name="group[5597][4]" id="mce-group[5597]-5597-2"><label for="mce-group[5597]-5597-2">Interest 3</label></li>
            </ul>
        </div>
        <div id="mce-responses" class="clear">
            <div class="response" id="mce-error-response" style="display:none"></div>
            <div class="response" id="mce-success-response" style="display:none"></div>
        </div>
    </div>
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file"><br>

    <div class="clear">
        <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
    </div>
</body>