簡體   English   中英

在PHP表單上引發問題

[英]Implode Issue On PHP Form

盡管事實上我可能看起來像個白痴,但我還是要發布整個文件來查看我做錯了什么。

我在頁面中內置了表單,如下所示:

<form method="post" class="form-horizontal" id="final_form" action="send_mail.php">
                 <h2>Search for your dream home<br />
       and save now!</h2>
                <legend>Which Areas are you interested in?</legend>
                <div class="areas row-fluid" style="text-align:left !important;">                       
                    <div class='span5' style='margin-left:0px !important;'>
                        <label>
                            <input type="checkbox" name="arrayValue[]" id="area[0]" value="Sparks" style='margin-top:-5px !important;'> Sparks</label>
                    </div>                      
                    <div class='span5' style='margin-left:0px !important;'>
                        <label >
                            <input type="checkbox" name="arrayValue[]" id="area[1]" value="Stead" style='margin-top:-5px !important;'> Stead</label>
                    </div>                      
                    <div class='span5' style='margin-left:0px !important;'>
                        <label>
                            <input type="checkbox" name="arrayValue[]" id="area[2]" value="North Reno" style='margin-top:-5px !important;'> North Reno</label>
                    </div>                      
                    <div class='span5' style='margin-left:0px !important;'>
                        <label >
                            <input type="checkbox" name="arrayValue[]" id="area[3]" value="South Reno" style='margin-top:-5px !important;'> South Reno</label>
                    </div>                      
                    <div class='span5' style='margin-left:0px !important;'>
                        <label >
                            <input type="checkbox" name="arrayValue[]" id="area[4]" value="Double Diamond" style='margin-top:-5px !important;'> Double Diamond</label>
                    </div>          
                    </div>
                <input type="button" onclick="jQuery('#myModal').modal('show')" value="CONTINUE" />


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

<!--banner area end-->
    <!--content area 1 start-->
    <div id="content1">
        <div class="content1_in"> <span> 
<h2 style="line-height:40px;font-size:40px;padding-bottom:10px">Some Content</h2>
<p style="line-height:30px;font-size:22px;text-align: left">Some Content!</p>
</span>

<div class="img">
               <img src="image" alt="" />
            </div>
        </div>
    </div>
    <!--content area 1 end-->
    <!--content area 1 start-->
    <div id="content2">
        <div class="content2_in"> <span> 

 </span>

            <div class="img">
                <img src="http://f14.co/realtor/assets/images/ipad-img.png" alt="" />
                <div class="key"></div>
            </div>
        </div>
    </div>
    <!--content area 1 end-->
    <!--content area 3 start-->
    <div id="content3">
        <div class="content3_in"> 
            <div class="img">
                <img src="image" alt=""     
/>
            </div>
            <div class="free"></div>
        </div>
    </div>
    <!--content area 3 end-->
    <div id="footer">
        <div class="footer_in">
            This Website Is Brought To You By: Ken Holden</div>
    </div>
    <!-- Modal -->
    <div id="myModal" class="modal hide fade modal-survey" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
             <h3 id="myModalLabel" class="survey_title">What type of home are you looking for?</h3>

        </div>

        <input type="hidden" name="template" id="template" value="Buyers" />
            <div class="modal-body">
                <div id="lead_info_1">
                    <div class="input select">
                        <div class=""></div>
                        <div class="span-4 step-2-dropdown append-bottom control-group">
                            <select class="span3 required" name="minPrice" id="minPrice">
                                <option value="">Price</option>
 <option value='$50,000 - $150000'>$50,000 - $150000</option><option value='$150,000 -    
$300,000'>$150,000 - $300,000</option><option value='$300,000 - $400,000'>

$300,000 - $400,000</option><option value='$400,000 +'>$400,000 +</option>                                   
</select>
                        </div>
                    </div>
                    <div class="input select">
                        <div class=""></div>
                        <div class="span-4 step-2-dropdown append-bottom control-group">
                            <select class="span3 required" name="minBedrooms" id="minBedrooms">
                                <option value="">Bedrooms</option>
<option value='1-2'>1-2</option><option value='2-4'>2-4</option><option value='4+'>4+   
</option>                                </select>
                        </div>
                    </div>
                    <div class="input select">
                        <div class=""></div>
                        <div class="span-4 step-2-dropdown append-bottom control-group">
                            <select class="span3 required" name="minBathrooms" id="minBathrooms">
                                <option value="">Bathrooms</option>
<option value='1-2'>1-2</option><option value='2-4'>2-4</option><option value='4+'>4+   
</option>                                </select>
                        </div>
                    </div>
                    <div class="input select">
                        <div class=""></div>
                        <div class="span-8 step-2-dropdown2 append-bottom control-group">
                            <select class="span3 required" name="realtor" id="realtor">
                                <option value="">Currently Working With a Realtor</option>
                                <option value="Yes">Yes</option>
                                <option value="No">No</option>
                            </select>
                        </div>
                    </div>
                    <div class="input select">
                        <div class=""></div>
                        <div class="span-8 step-2-dropdown2 append-bottom control-group">
                            <select class="span3 required" name="move" id="move">
                                <option value="">When Do You Plan On Moving?</option>
                                <option value="30-90 days">30-90 days</option>
                                <option value="90-120 days">90-120 days</option>
                                <option value="I'm just looking">I'm just looking</option>
                            </select>
                        </div>
                    </div>
                    <!--<img src="http://localcommissionsystem.com/assets/app/images/SearchDealsLikeThis.png" />-->
                </div>
                <div id="lead_info_2" style="display:none">
                    <center>

                    </center>
                </div>
                <div id="lead_info_3" style="display:none">

                    <textarea class="" id="wantedArea" name="wantedArea" style="display:none;"></textarea>
                    <div class="control-group">
                        <label class="control-label" for="fname">First Name</label>
                        <div class="controls">
                            <input class="required" type="text" id="fname" name="fname" placeholder="First Name" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="email">Email</label>
                        <div class="controls">
                            <input class="required" type="text" id="email" name="email" placeholder="Valid Email Required" />
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="phone">Cell Phone</label>
                        <div class="controls">
                            <input class="required" type="text" id="phone" name="phone" placeholder="Cell Phone" />
                        </div>

                    </div>


    </div>
            </div>

這是PHP

<?php

$webmaster_email = "email@email.com";

$webmaster_email2 = "email@email.com";

$fname = $_REQUEST['fname'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$minBedrooms = $_REQUEST['minBedrooms'];
$minBathrooms = $_REQUEST['minBathrooms'];
$minPrice = $_REQUEST['minPrice'];
$move = $_REQUEST['move'];
$realtor = $_REQUEST['realtor'];

if( !empty($_REQUEST) && is_array($arrayValue) ) {

$arrayValue = array();
$areas = implode("," , $_REQUEST['arrayValue']);

}




$emailfrom = $_REQUEST['email'];



$headers = 'From: '.$emailfrom."\r\n".

$email_to = "test@gmail.com, ";

/* This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "index.html";
$thankyou_page = "thankyou.html";


/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC    
list.
*/
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;
}


}

// If the user tries to access this script directly, redirect them to the feedback    
form,
if (!isset($_REQUEST['email'])) {
header( "Location: $feedback_page" );
}


// If email injection is detected, redirect to the error page.
elseif ( isInjected($email) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( $email_to, "You Have a New Lead",
"Name: $fname\nEmail: $email\nPhone: $phone\nMinBedrooms: $minBedrooms\nMinPrice:     
$minPrice\nMove Date: $move\nRealtor: $realtor\nAreas: $areas", $headers );
}

echo "<script>window.location = 'thankyou.html'</script>"; 
?>

我的復選框未返回任何值。 有人知道為什么嗎? 我一直在努力使事情變得正確,並且由於另一個問題的幫助,我認為陣列的設置正確,但是我認為我在其他帖子中提出的問題是錯誤的。

$arrayValue沒有在第一個if語句之前定義,這就是為什么is_array($arrayValue)無法成功的原因。 請試試:

if( !empty($_REQUEST['arrayValue'])) {
  $arrayValue = array();
  $areas = implode("," , $_REQUEST['arrayValue']);
}
In your HTML this should be the name:

 <input type="checkbox" name="arrayValue" id="area[4]" value="Double Diamond" style='margin-top:-5px !important;'> Double Diamond</label>

在你的PHP中

 if( !empty($_REQUEST) && is_array($arrayValue) ) 
       {

      $arrayValue = array();
      $arrayValue[] = $_REQUEST['arrayValue'];
       }
      $areas = implode(",",$arrayValue); 

 put it in the array first then implode it as a string.       

只需在您的php上打印php全局變量$ _REQUEST即可檢查。 您可以通過編寫print_r($ _ REQUEST);來實現。 如果沒有顯示任何內容或黑色數組,請在PHP文件的每個位置使用$ _POST而不是$ _REQUEST。 希望它能解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM