一个php 文件与多个html文件如何进行交互

一直都是用框架很简单,突然想自己手写一个发现不会。
就是很简单的画面类似注册。
一个php和三个html(输入页,确认页,完了页)。
我想要的效果是输入页输入完提交,php去check有问题提示没问题页面跳转到确认页。确认页提交就跳到完了页。
问题就是输入页action提交phpcheck完后如果将错误信息的数组返回到输入页。
如何将错误信息返回到输入页进行显示。php和html两个不同的页面之间的绑定是用require_once吗

  <?php

  header("Content-type: text/html; charset=gb2312");

  header("Pragma: no-cache");

  header("Expires: 0");

  @$action = $_REQUEST ['action'];

  $sid = MyTool::generateId ();

  if (! $action)

  $action = "list";

  Trace::debug ( $action );


  if ($action == "save") {

  $reply = $_REQUEST ['reply'];//获取回复值

  print_r($reply);

  $id = $_REQUEST ['f_id'];

  CourseService::updateApplyState($db,$id,TrainApply::STATUS_PASS);


  $apply=CourseService::getTrainApply($db,$id);


  $student=$apply->owner;

  $trainId=$apply->train;


  $train=CourseService::getTrainSchedule($db,$trainId);


  $pass_test=$train->test==""?0:-1;

  $pass_judge=$train->judge==""?0:-1;

  $pass_readrate=$train->readrate==""?0:-1;

  $pass_feedback=$train->feedback==""?0:-1;


  $mc = new MyCourse();

  $mc->schedule_id = $train->id;

  $mc->course_id = $train->course_id;

  $mc->user_id = $student;

  $mc->type = $train->catalog;

  $mc->state = MyCourse::STATE_WAITING;

  $mc->pass_test = $pass_test;

  $mc->pass_judge =$pass_judge ;

  $mc->pass_feedback = $pass_feedback;

  $mc->pass_readrate = $pass_readrate;

  $mc->score = $train->score;

  $mc->starttime = $train->starttime;

  $mc->endtime = $train->endtime;

  $mc->coursename = $train->name;

  CourseService::save($db, $mc);


  print"<script>alert('通过操作成功!');window.close();location.href='applyreply.php?action=list'</script>";

  }

  if ($action == "reject") {

  $id = $_REQUEST ['f_id'];

  $sql = "update t_train_apply set f_status=2 where f_id='".$id."'";

  Trace::debug ( $sql );

  $db->Execute ( $sql );

  print"<script>alert('拒绝操作成功!');window.close();location.href='applyreply.php?action=list'</script>";

  }

  if ($action == "list") {

  $pagination = new MyPagination(0,1);

  $UserID = $_SESSION[AuthorizationHelper::SESSION_USER_KEY]['id'];

  $as = CourseService::listApply($db,$pagination,null,null,null,$UserID);

  //print_r($as);

  ?>

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

  <title>无标题文档</title>


  <?= HTMLTool::includeResource() ?>

  <link href="../css/css.css" rel="stylesheet" type="text/css" />

  <script language="JavaScript">

  $(function() {

  $('#tabs').tabs({spinner:'加载...',fx:{ opacity: 'toggle' },selected:2});

  });

  function passIt(id){

  var url = '<?php print $_SERVER['PHP_SELF'] ?>';

  var pars = 'action=pass&f_id='+id;

  alert(url+"?"+pars);

  // open(url+"?"+pars);

  var myAjax = new Ajax.Request(

  url,

  {

  method: 'get',

  parameters: pars,

  onComplete:done

  });

  afterPass(id);

  }


  function afterPass(id){

  // alert(originalRequest.responseXML);

  // var result = originalRequest.responseXML.getElementsByTagName("id");

  // alert(result.length);

  document.getElementById('button_'+id).style.display='none';

  document.getElementById('status_'+id).innerHTML='通过';

  }

  function rejectIt(id){

  var url = '<?php print $_SERVER['PHP_SELF'] ?>';

  var pars = 'action=reject&f_id='+id;

  //alert(url+"?"+pars);

  var myAjax = new Ajax.Request(

  url,

  {

  method: 'get',

  parameters: pars,

  onComplete:done

  });

  afterReject(id);

  }


  function afterReject(id){

  // alert(originalRequest.responseXML);

  // var result = originalRequest.responseXML.getElementsByTagName("id");

  // alert(result.length);

  document.getElementById('button_'+id).style.display="none";

  document.getElementById('status_'+id).innerHTML="驳回";

  }


  function done(){

  alert("操作成功");

  }

  </script>

  </head>


  <body >

  <!-- 导航栏 -->

  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" id="navigationbar"  class="navigationbar">

  <tr><td height="28" >您现在的位置: <a href="../welcom.php">首页</a> >> <a href="#">考试管理</a> >>考试申请管理</td></tr>

  </table>

  <table width="98%" border="0" cellpadding="0" cellspacing="0" align="center">

  <tr>

  <td valign="top">

  <table width="100%" border="0" cellpadding="1" cellspacing="1" class="listtable">

  <thead>

  <tr>

  <td width="150">考试名称</td>

  <td>申请原因</td>

  <td width="150">申请人</td>

  <td width="130">申请时间</td>

  <td width="80">状态</td>

  <td width="80">管理</td>

  </tr>

  </thead>

  <?php

  //foreach($as as $a){

  //Trace::debug($a);

  //$schedule = CourseService::getTrainSchedule($db,$a->train);

  //$u = UserService::getUser($db,$a->owner);

  ?>

  <tr>

  <td><?= $schedule->name ?></td>

  <td><?= $a->name ?></td>

  <td><?= $u->trueName ?></td>

  <td><?= MyTool::formatDate($a->createtime)?></td>

  <td><span id="status_<?= $a->id ?>"><?= TrainApply::$STATUS_ARRAY[$a->status]?></span></td>

  <td>&nbsp;<span id="button_<?= $a->id ?>">

  <?php if($a->status==TrainApply::STATUS_WAITING) {?>

  <a href="?action=pass&f_id=<?= $a->id ?>">通过</a>&nbsp;

  <a href="application_manage.php?action=reject&f_id=<?= $a->id ?>">拒绝</a>

  <?php } ?>

  </td>

  </tr>

  <?php //} ?>

  </table>

  <?php include($_SERVER['DOCUMENT_ROOT']."/train/common/pagination.php")?>

  </td>

  </tr>

  </table>


  </body>

  </html>

  <?php }?>

  <?php if($action=="pass") {//回复

  ?>

  <html>

  <head>

  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

  <title>无标题文档</title>


  <?= HTMLTool::includeResource() ?>

  <script >

  $(document).ready(function(){

  $("#commonForm").validate();

  });

  </script>

  </head>


  <body>


  <table width="98%" border="0" cellspacing="0" cellpadding="0">

  <tr>

  <td>

  <table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

  <td  class="border_left_up"></td>

  <td  class="border_middle_up"><span class="pagetitle">建议回复</span></td>

  <td  class="border_right_up"></td>

  </tr>

  </table>

  </td>

  </tr>

  <tr>

  <td align="center">

  <table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

  <td class="border_left_middle">&nbsp;</td>

  <td align="center">

  <form id="commonForm" method="post">

  <input type="hidden" name="action" value="save"/>

  <input type="hidden" name="id" value="<?php print $_REQUEST ['id']?>" />

  <textarea class="required" rows="10" cols="120" name="reply" maxlength="500">您的建议已采纳,谢谢参与</textarea><br>

  <span class="btn_green"><span><button type="submit" id="sure">提 交</button></span></span>

  </form>

  </td>

  <td  class="border_right_middle">&nbsp;</td>

  </tr>

  </table>

  </td>

  </tr>

  <tr>

  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>

  <td  class="border_left_down"></td>

  <td  class="border_middle_down">&nbsp;</td>

  <td  class="border_right_down"></td>

  </tr>

  </table></td>

  </tr>

  </table>

  </body>

  </html>


  <?php } ?>

      

    就是你要的效果,,看仔细点      åªçœ‹æ ‡ç­¾ä¸Žåˆ¤æ–­å°±è¡Œ
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-11-13
不用框架,也不用模板技术,那就直接把HTML跟PHP混编即可,后缀为PHP。追问

谢谢 谢谢 都写在php文件里的那种方法我知道,其实我想知道的是一个php里面写逻辑,表示的部分分成3个不同的html。就是html和php之间数据传输不太清楚。
谢谢啦

追答

其实你得先明白一个概念,什么叫做模板技术,,其实模板也只是通过PHP程序把HTML文件内容通过特定的函数来解析HTML里面特定的标签(特殊规则字符),然后输出,最后出来的东西还是混编的东西,建议你看看UCHOM的源码就明白了。。。如果硬要说PHP如何跟HTML中间传输数据,只有AJAX了。。

第2个回答  2014-11-13
通过session存储就行了。

追问

谢谢 不是不认可你的方法 就是个人不是很喜欢 session里存数据 ^^

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网