php访问html代码中的会话变量值

时间:2015-10-24 11:31:57

标签: javascript php html

我想要实现的是在html上打印php会话变量form.Above是我试图打印valid_firm Session变量的形式,但是它用于打印变量的方式不是工作... newFirm-form.php的

<!DOCTYPE>
 <html>
  <head>
    <meta charset="utf-8">
    <meta content="no-cache" http-equiv="cache-control"></meta>
  </head>

<body>
  <form id="firm-form" method="post" />
      <p>Firm Name</p><input class="firm-name" type="text" name="firm-name"  />

      <p>Email</p><input type="text" name="firm-email" />
      <p>Telephone</p><input type="text" name="telephone" />
      <p>Address</p><input type="text" name="address" />
      <p>City</p><input type="text" name="city" />
      <p>Firm Code</p><input type="text" name="firm-code" /> <br/>
  </form>
  <?php print $_SESSION["valid_firm"]; ?>
  <input class="submit" type="submit" value="Submit"><br />
  <span class="error" style="display:none"> Please Fill The Empty Fields</span>
  <span class="success" style="display:none"> Form Submitted Success</span>


</body>
<footer>
  <script type="text/javascript" src="../js/libs/jquery-1.11.3-min.js">     </script>
  <script type="text/javascript" src="../js/newFirm.js"></script>
  </footer>

 </html>

javascript文件用ajax post方法调用提交表单

  $(document).ready(function() {
     var empty_fields = 0;
     $(".submit").on("click", function(){
       $("#firm-form *").filter(":input").each(function(){
      if(!$(this).val()){
      empty_fields += 1;
    }
  });
  if(empty_fields > 0){
    $(".error").fadeIn(800).show();
    $(".success").fadeOut(800).hide();
  }
  else {
    var firm_name = $(".firm-name").val();
    $.ajax({
      type:"POST",
      url:"../registration-control/register-firm.php",
      data: "firm_name=" + firm_name,
      success: function(){
        $(".success").fadeIn(800).show();
        $(".error").fadeOut(800).hide();
      }
    });
  }
  empty_fields = 0;
    });

  });

和用于保存会话变量的php文件

<?php
if (isset($_POST["firm_name"])){
  validateName($_POST["firm_name"]);

$_SESSION["firm"] = $_POST["firm_name"];
 //echo $_SESSION["firm"]." from register-firm";
  }

   function validateName($firm_name){
       var_dump($firm_name);
      if (preg_match("/^[A-ZΑ-Ω]{1}[a-zA-Zα-ωΑ-Ω0-9\.]*/", $firm_name) &&         !ctype_digit($firm_name)){
     $_SESSION["valid_firm"] = 1;
   }
   $_SESSION["valid_firm"] = 0;
  }
 ?>

1 个答案:

答案 0 :(得分:2)

我不知道在您要访问会话的每个页面中,您的session_start()首次调用此函数的位置

<强> EDITED

我能说什么,谢谢你的-1。

当我说session_start()我做了session_start()因为能够在PHP脚本中访问会话时,您必须先致电$_SESSION才能致电session_start()。更多的是<!DOCTYPE html>应该在private void setSpans(Editable s, @ColorInt int backgroundColor) { BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); String[] words; if (s.toString().endsWith(" ")) { words = (s.toString() + "X").split("\\s"); } else { words = s.toString().split("\\s"); } int completedWordsCount = words.length - 1; if (spans.length != completedWordsCount) { for (BackgroundColorSpan span : spans) { s.removeSpan(span); } int currentIndex = 0; for (int i = 0; i < words.length-1; i++) { s.setSpan(new CustomDrawble(Color.GRAY, Color.WHITE), currentIndex, currentIndex + words[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); currentIndex += words[i].length() + 1; } } 之前的任何响应之前被调用。