0

カスタム検証があるときに送信を押しても、php ファイルを実行できません。ドロップダウン ボックスでその他を選択すると、テキスト ボックスが表示されます。送信を押すと、php ファイルは実行されません。このカスタム検証なしでドロップダウンで値を選択すると、php ファイルが実行されます。

<body>
<form action="form-to-email.php" method="post" name="LeaveRequestPart1" id="LeaveRequestPart1">
    <table class="LeaveRequestPart1" align="center">

<tr>
    <td colspan="2"><font color="red">*</font>
        <label>Type of Leave</label>
            <select name="TypeOfLeave" id="TypeOfLeave" onchange =
           "if(this.value=='Other'{this.form['Other'].style.visibility='visible'}else {this.form['Other'].style.visibility='hidden'};">
                <option value="N/A"></option>                       
                        <option value="Vacation">Vacation</option>
                        <option value="Illness">Illness</option>
                        <option value="FamilyIllness">Family Illness</option>
                        <option value="Bereavement">Bereavement</option>
                        <option value="PersonalWithPay">Personal - with pay</option>
                        <option value="PersonalWithoutPay">Personal - without pay</option>
                        <option value="JuryDuty">Jury Duty</option>
                        <option value="Military">Military</option>
                        <option value="Pallbearer">Pallbearer</option>
                        <option value="Professional" id="Professional">Professional</option>
                        <option value="Routine" id="Routine">Routine - overnight</option>

                <option value="Other">Other</option>
            </select> 
            <input type="text" name="Other" id="Other" style="visibility:hidden;" />
    </td>
</tr>
        </table>
</form>
</body>

</html>

PHPコード

<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "Form Error; You need to submit the form. ";
}

//Form Variables
$ID = $_POST['ID'];
$Name = $_POST['Name'];
$CampusLocation = $_POST['CampusLocation'];
$TypeOfRequest = $_POST['TypeOfRequest'];
$TypeOfLeave = $_POST['TypeOfLeave'];
$Other = $_POST['Other'];


   //Validate first
   if(IsInjected($SEmail))
   {
       echo "Bad email value!";
       exit;
    }

if(IsInjected($YEmail))
    {
        echo "Bad email value!";
        exit;
    }

$Email_subject = "Leave Request Submitted";

//Start of Email body. Do not remobe BODY commands
$Email_body = <<<BODY

Employee ID: $ID
Name: $Name
Campus: $CampusLocation
Type of Request: $TypeOfRequest
Type of Leave: $TypeOfLeave
Other Type of Leave: $Other

Employee CCC email address: $YEmail@cccneb.edu
BODY;
//End of Email body

// single email address 

$to = "$SEmail@cccneb.edu";
$to2 = "$YEmail@cccneb.edu";


// multiple recipients
//$to  = 'YEmail@cccneb.edu' 

//Email From & Reply
$headers = "From: $to2 \r\n";
$headers .= "Reply-To: $to2 \r\n";

//Send the email!
mail($to,$Email_subject,$Email_body,$headers);

//done. redirect to thank-you page.
header('Location: form-end.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
    $injections = array('(\n+)',
          '(\r+)',
          '(\t+)',
          '(%0A+)',
          '(%0D+)',
          '(%08+)',
          '(%09+)'
          );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
      {
          return true;
      }
  else
      {
          return false;
      }
}

?> 
4

1 に答える 1

1

ページで JavaScript エラーがスローされているかどうかを確認します。イベントにエラーが表示されますonChange- に閉じ括弧がありませんif。試す

<select name="TypeOfLeave" id="TypeOfLeave" 
    onchange="
        if(this.value == 'Other') {
            this.form['Other'].style.visibility = 'visible';
        } else {
            this.form['Other'].style.visibility = 'hidden';
        }">

次の場合は三項も使用できます

onchange="this.form['Other'].style.visibility = (this.value == 'Other') ? 'visible': 'hidden';"
于 2012-11-15T21:41:47.957 に答える