0

ユーザーが名、姓、電子メールを入力できるフォームがあります。送信をクリックするだけで、より多くのユーザーに送信したい場合は、このフォームを複数回送信できます (もちろん、サニテーションと検証を使用してフィールドが正しく入力されている場合に限ります)。

if (isset($_POST['Submit'])) {
//sanitize if field (like email) is not empty, then validate it using a function
// such as FILTER_VALIDATE_EMAIL and FILTER_SANITIZE_STRING
//like if ($_POST['email'] != "") { do the sanitation and validation here }
//then if no error send the email
//then $_POST = array(); to clear up form for the next entry
}

<form> form here</form>

このコンセプトをレイアウトするだけでアイデアはありますか?それともサンプルコードが必要ですか? ご協力いただきありがとうございます。

ジョーが提案したものを使用しようとしましたが、うまくいきませんでした。さらに助けはありますか?

session_start(); 
 if (isset($_POST['Submit'])) {
   if (isset($_SESSION['submission_count'])) {
     if ($_SESSION['submission_count'] > 10) {
      echo "You can't submit so many!";
      exit;
     }
   }
else {
  $_SESSION['submission_count'] = 0;
}
$_SESSION['submission_count'] += 1;
   // Form validation and sanitation
   // Send email 

  }

 ?>

<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
First Name:
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" size="50" /><br />
Last Name:
<input type="text" name="lastname" value="<?php echo $_POST['lastname']; ?>" size="50" /><br />
Email Address: 
<input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> <br/><hr />

<br/>
<input type="submit" class="button" name="Submit" />
</form>
4

1 に答える 1

1

にカウンターを収納できます$_SESSION

http://www.php.net/manual/en/intro.session.php

<?php 
// Starting the session 
session_start(); 
if (isset($_POST['Submit'])) {
  if (isset($_SESSION['submission_count'])) {
    if ($_SESSION['submission_count'] > 5) {
      echo "You can't submit so many!";
      exit;
    }
  }
  else {
    $_SESSION['submission_count'] = 0;
  }
  $_SESSION['submission_count'] += 1;
  // Do the rest of your form submission
}
于 2013-09-18T22:57:50.700 に答える