首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >中的表单不重定向到php。

中的表单不重定向到php。
EN

Stack Overflow用户
提问于 2016-06-08 06:43:11
回答 3查看 1.4K关注 0票数 2

网站来源:http://www.salefee.com/

有人能查一下我上面提到的网站吗.我在“收卖故事电子书,提交你的电子邮件”下做了一份表格

我做了一个表单,用户提交他的电子邮件id,然后表单是链接到一个php文件发送电子邮件到用户电子邮件id。问题是表单没有被重定向到.php文件。我在HTML中添加了actionmethod属性。当用户单击submit按钮时,不会执行php代码。

HTML代码如下:

代码语言:javascript
复制
    <!-- Mailchimp Newsletter -->
              <div style="text-align:center">  
              <div class="newsletter-wrapper animateblock rtl-2 speed-1">
                <form action="story.php" method="post" class="form-inline subscription-mailchimp">
                  <div class="form-group input-group input-newsletter">
                    <input class="form-control" id="newsletter-email" name="newsletter-email" type="email" placeholder="Enter email">
                    <div class="input-group-btn">
                      <button class="btn btn-danger" type="submit">Sign Up</button>
                    </div>
                  </div>
                  </form>
                  <small class="help-block">Don't worry. We do not spam :)</small>
              </div>
              </div>
<!-- End Mailchimp Newsletter -->

我的php代码名为story.php,如下所示:

代码语言:javascript
复制
<?php
if ($_POST) {
  $to_email = "salefee12@gmail.com" //Recipient email, Replace with own email here


  //Sanitize input data using PHP filter_var().
  $user_trial_email   = filter_var($_POST["newsletter-email"], FILTER_SANITIZE_EMAIL);

  //additional php validation
  if (!filter_var($user_trial_email, FILTER_VALIDATE_EMAIL)) { //email validation
    $output = json_encode(array('type'=>'error', 'text' => 'Please enter a valid email.'));
    die($output);
  }

  //subject
  $subject = "The Story";

  //email body
  $message_body = "Email  : ".$user_trial_email."\r\nApp link:https://play.google.com/apps/testing/com.salefee.salefee.salefee\r\nWe will shortly send you the whole story";

  //proceed with PHP email.
  $headers = 'From: '."salefee12@gmail.com".''."\r\n".
  'Reply-To: '.$user_trial_email.''."\r\n".
  'X-Mailer: PHP/'.phpversion();

  $send_mail = mail($to_email, $subject, $message_body, $headers);

  if (!$send_mail)
  {
    //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
    $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
    die($output);
  } else {
    $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_trial_name.', Thank you for subscribing. You will soon get a link to download app.'));
    die($output);
  }
}
?>

有人能帮我把这个code...Thanks提前!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-06-08 07:01:16

首先,您需要为提交按钮指定名称:

代码语言:javascript
复制
<button class="btn btn-danger" type="submit" name="submit">Sign Up</button>

然后在php文件中:

代码语言:javascript
复制
if (isset($_POST("submit")) {
票数 3
EN

Stack Overflow用户

发布于 2016-06-08 07:36:29

PHP:

代码语言:javascript
复制
if ($_POST['signup']) {
//your script which you want to execute as soon as form submitted
}

HTML:

代码语言:javascript
复制
<button class="btn btn-danger" type="submit" name="signup">Sign Up</button>

了解有关如何使用$_POST[]的更多信息

http://php.net/manual/en/reserved.variables.post.php

票数 1
EN

Stack Overflow用户

发布于 2016-06-08 07:30:51

在PHP中,数据是通过名称而不是id传递的。所以HTML代码应该如下所示

<input class="form-control" id="newsletter-email" **name**="newsletter-email" name="newsletter-email" type="email" placeholder="Enter email">

如果您得到这样的数据,那么PHP文件应该可以工作。

代码语言:javascript
复制
$_POST["newsletter-email"]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37695053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档