2014-01-11 2 views
0

다음 echo 문은 빈 텍스트 상자와 php를 사용하는 제출 단추를 만듭니다.제출시 유효성 입력 입력이 비어 있지 않음

echo"<td><form id=\"edit\" name=\"edit\" method=\"post\" action=\"../assets/modules/coursemanager/process.cm.php\" onsubmit=\"return check_edit();\"> 
    <input type=\"text\" size=\"3\" id=\"edit_places\" name=\"edit_places\" value=\"\" /> 
    <input type=\"hidden\" name=\"sid\" value=\"".$sid."\" /> 
    <input type=\"submit\" name=\"Submit\" value=\"edit places\" /></form></td>"; 

위의 양식은 내가 사용하고있는 유효성 검사 JavaScript이지만 무시해도됩니다.

function check_edit(){ 
     var notempty=document.forms["edit"]["edit_places"].value; 
     if(notempty==null || notempty==""){ 
      alert("Please enter the new number of available places and try again"); 
      return false; 
     }else{  
      return true; 
     } 
    } 

누군가 내 오류를 표시 할 수 있다면 매우 감사 할 것입니다.

+0

문제가 아닌지 확실하지 않지만'notempty == nul || notempty == ""''notempty == null || notempty == ""'. 또한 Javascript가 작동하는 방식 때문에 'null'과 '' ''을 처리하지만 '정의되지 않음', 'false'및 '0'도 처리하는 'if (! notempty)'가 더 간단합니다. 'null' /''''만 체크하고 싶다면'=='대신'==='를 사용해야합니다. – machineghost

+0

세 번째 줄에 'null'이 잘못 표기되어 있습니다. –

+0

아, 예. 조쉬에게 감사드립니다. 게시물에서 그 부분을 바로 잡았습니다. – Twobears

답변

1

입력 길이를 확인할 수 있습니다.

+0

Knouroozi 님의 답변에 감사드립니다. 나는 다음과 같이 그것을 해결했다 : – Twobears

0

트릭을 수행하고 check_edit 기능이없는 처리 스크립트에서 else 문을 사용했습니다.

if($_POST['edit_places']!== ''){ 
    $id=$_POST['sid']; 
    $z=$_POST['edit_places']; 
    $sql = "UPDATE xtra_session SET places=$z WHERE xtra_session.id=$id"; 
    $add = $modx->db->query($sql); 
    $msg = ($add? "available places has been updated" : "error: ".mysql_error()); 
    } 
    else { 
    echo "Please enter a number of places to change"; 
    } 

귀하의 소중한 의견에 감사드립니다.

관련 문제