2013-06-26 2 views
-1

안녕하세요 저는 이전 호에 대한 다음 호에 대한 답변을 찾지 만 시도 할 수 없었습니다. 내가 잘못 읽은 부분을 강조 표시 할 수 있습니까?PHP에서 동적으로 채워진 텍스트 상자 필드 유효성 검사

내 문제는 텍스트 상자에 값이 있거나 비어 있는지 여부에 관계없이 Save 단추를 클릭 할 때마다 항상 저장 됨 메시지를 인쇄합니다. 단순히 텍스트 상자에서 값의 유효성을 검사하지 않습니다.

또한 텍스트 상자는 루프를 통해 채워집니다.

감사합니다.

<?php 
SESSION_start(); 
if(!isset($_SESSION['userLogin'])) 
{ 
header('Location:../2-lo'); 
} 


include ("../connection/index.php"); 

?> 
<?php 
    function putForm2(){ 
    $myForm = "<form name='form2' method='post' action=''><table border='1'><tr><td>form 2 is here!<br></td></tr><tr><td><input type='text' name='txt123' id='txt123'></td></tr> <tr><td><input type='submit' name='sendtwo' id='sendtwo' value='TwoClick'></td></tr></table></form>"; 
    return $myForm; 
    } 
?> 
<!DOCTYPE html> 
<html> 
<head><title></title> 
</head> 
<body> 
<div id="One"> 
    <form name="form1" method="post" action="#"> 

<?php 
$SQLbrands="SELECT * FROM brands"; 
$runBrands=mysqli_query($db, $SQLbrands) or die ("SQL Error"); 
$noRow=mysqli_num_rows($runBrands); 


$brndTable = "<table border='1' cellspacing='0' cellpadding='1' id='brndTable1' class='brndTable1'>"; 
$brndTable .= "<thead><tr><th class='brT11'>Brand Name</th><th class='brT21'>Variant</th><th class='brT31'>SKU</th> 
         <th class='brT41'></th></tr></thead>"; 
$brndTable .= "<tbody>"; 
while ($reK = mysqli_fetch_array($runBrands)) 
{ 
    $wec = $reK['id']; $wec2 = $reK['bvariant']; $wec3 = $reK['bsku']; 
    $brndTable .= "<tbody class='colormine'><tr>"; 
    $brndTable .= "<td class='brT1'>".$reK["bname"]."</td>"; 
    $brndTable .= "<td class='brT2'>".$reK["bvariant"]."</td>"; 
    $brndTable .= "<td class='brT3'>".$reK["bsku"]."</td>"; 
    $brndTable .= "<td class='brT4'><input type='checkbox' name='delz[]' value='$wec' ></td>"; 
    $brndTable .= "</tr>"; 
} 
$brndTable .= "</tbody>"; 
$brndTable .= "</table>"; 


echo $brndTable; 
?> 

       <input type="submit" name="sendone" id="sendone" value="OneClick"> 
    </form> 
</div> 

<div id="two"> 


      <?php 

      if(isset($_POST['sendone'])) 
      { if(!isset($_POST['delz'])) 
       {echo 'No check boxes are selected!'; return;} else 
       { 
       $mohan = "<form method='post' action=''><table border='1' id='myTad' cellspacing='0' cellpadding='2'> 
        <tr class='tabColor'> 
        <td>Brands</td> 
        <td>Scheme</td> 
        <td>Allocation</td> 
        <td>Focus Channels</td> 
        <td>Focus Provinces</td> 
        </tr>"; 
       foreach($_POST['delz'] as $delz) 
          { 
           $delz=mysqli_real_escape_string($db,$delz); 
           $QR = "SELECT bname, bvariant, bsku FROM brands WHERE id='$delz'"; 
           $rr = mysqli_query($db,$QR) or die ("SQL Error"); 
           $roV = mysqli_num_rows($rr); 
           $rr = $rr->fetch_assoc(); 

           $mohan .= "<tr class='sc_eght' ><td class='sc_five'>".$rr['bname']." ".$rr['bvariant']." ".$rr['bsku']; 
           $mohan .="</td> 
            <td><textarea style='width:80px;' name='schema[]' id='vtext' class='sc_one' rows='1' cols='1' maxlength='100'></textarea></td> 
            <td><input style='width:80px;' type='text' name='allocas[]' id='vtext' class='sc_two' size='80' maxlength='5'></td> 
            <td><input style='width:80px;' type='text' name='channelz[]' id='vtext' class='sc_three' size='120' maxlength='30'></td> 
            <td><input style='width:80px;' type='text' name='provinz[]' id='vtext' class='sc_four' size='120' maxlength='30'></td> 
            </tr>"; 

          } 
           $mohan .= "<input type='submit' name='sendMe' id='sendMe' value='Save'></table></form>"; 
           $_SESSION['cb'] = $mohan; } 

           if(isset($_SESSION['cb'])) 
           echo $_SESSION['cb']; 
      } 


if(isset($_POST['sendMe'])) 
{ 
    if($_POST['provinz'] == "") 
    {echo $_SESSION['cb']; echo "Province is empty!"; return;} else { echo $_SESSION['cb']; echo "Saved!"; return;} 

    if(!isset($_POST['allocas']) || $_POST['allocas'] == '') 
    {echo $_SESSION['cb']; echo "Allocation is empty!"; return;} else { echo $_SESSION['cb']; echo "Saved!"; return;} 

} 

      ?> 

     </div> 
    </body> 
</html> 
+0

제안 사항, html-php mix는 매우 혼란 스럽습니다. 코드가 php와 html로 분리되어 있으면 더 잘 이해할 수 있고 디버깅 할 수 있습니다. –

+0

중복 [동적 텍스트 상자 값이 유효성 검사에서 캡처되지 않습니다 - PHP] (http://stackoverflow.com/questions/17280029/dynamic-text-box-value-doesnt-capture-in-validation-php) – CBroe

+0

@ CBroe는 내 질문을 여기에서 읽었습니까 ?? –

답변

0
if(!isset($_POST['allocas']) || $_POST['allocas'] == '') 

가 문제 라인 될 가능성이 높습니다. allocas가 설정되어 있지 않거나 설정되어 있지만 비어 있으면 true를 반환합니다. 당신이 의미 아마도 원하든

했다 : allocas 텍스트가 포함 된 경우에만 true를 돌려줍니다

if(!(isset($_POST['allocas']) || $_POST['allocas'] == '')) 

.

+0

친구가 없습니다! 여전히 작동하지 않습니다! –

관련 문제