donglian7879 2015-01-03 17:14
浏览 56

将多页php表单转换为一个页面表单

Good day all, I have got the following question: I have got a multipage webform which is working good exept every step makes webpages reload. Now it is a time to move to a single page with steps. I have studied lots of variation which I could find over the google but got lost :(

The problem is that everypage exept the front step uses data from database, which is selected on previous user input. Can you please provide an example how to handle the form.

Form (simple) details:

Step1.php - simple php query to database for selet fields Step2.php - display options depending on user answers is step1, also store some step1 detailes for future Step3.php - more detailed input depending on step1 and step2 results step4.php verivication, calculation store data in mysql call extrenal scripts

Any ideas? (I know my question can be really easy for a geeks but not for me as I am still learning.

i have tried is the following code:

<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
function call() {
  var msg   = $('#formx').serialize();
    $.ajax({
      type: 'POST',
      url: 'check.php',
      data: msg,
      success: function(data) {
        $('.results').html(data);
      },
      error:  function(xhr, str){
            alert('error: ' + xhr.responseCode);
        }
    });

    }
</script> 
<form method="post" action="javascript:void(null);" id="formx" onsubmit="call()"> here some data 
<input type="submit" value="Submit"/> </form> <div id="results"></div>    
  • 写回答

1条回答 默认 最新

  • doufen3786 2015-01-03 20:03
    关注

    This solution consists of echoing the forms you had which receive get parameters to do their respective queries. This ones are retrieved by ajax and using jquery appended to the right div

    replace the submit button for a

        <a onClick='action1'>submit</a>
    

    have your forms within a form and make 4 php's which look like your former forms

    this is an example I've used

    function contreportes(e){
        var res=e.target.responseText;//get new form
        $("table#productos tbody").append(res); //put it in place
    
    }
    
    function a(){
         //variables to send
        var codigo = document.getElementById('barcode').value;
        var cantidad = document.getElementById('cantidad').value;
        var id_presentacion = document.getElementById('id_presentacion').value;
        var porcentajedesc = document.getElementById('porcentajedesc').value;
    
            var url="/administracion/cotizacion/getproducto/?codigo="+codigo+"&cantidad="+cantidad+"&id_presentacion="+id_presentacion+"&porcentajedesc="+porcentajedesc;
            var datos=new FormData();  //generando un obj de un formulario que se va a crear virtualmente
            var solicitud=new XMLHttpRequest();
    
            solicitud.addEventListener("load",contreportes,false);
            solicitud.open("GET",base,true);
            solicitud.send(datos);
    
    
    }
    

    There must be an easier way but this is how i go about it

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。