简体   繁体   English

保存输入->值而不嵌入PHP

[英]Saving input->values without embed php

Main problem is values written in input elementss disseapear after page reload (submit , refresh etc.) 主要问题是页面重新加载(提交,刷新等)后消失在输入元素中的值消失

I have a completed form ... /form element. 我有一个完整的表格... / form元素。 Traditionally, I can insert a php line. 传统上,我可以插入php行。

<input value="<?php if(isset($_POST['foo']))echo $_POST['foo'] ?>">

This solves the submit part. 这解决了提交部分。 However, I feel that this is the worst solution, in my case. 但是,就我而言,我认为这是最糟糕的解决方案。 I have hundreds of input elements in my form. 我的表单中有数百个输入元素。 There are even some inputs to produce input tables. 甚至有一些输入可以产生输入表。 Number of input elements are so much that i became curious about finding a work around. 输入元素的数量如此之多,以至于我对寻找解决方法感到好奇。

Is there a way to store input->values before the submit operation and inject them after page reload? 有没有一种方法可以在提交操作之前存储输入->值,并在页面重新加载后注入它们? So that, the user can upload a file, file will be parsed by php core. 这样,用户就可以上传文件,文件将被php core解析。 And when the page reloaded both user originated inputs and file originated values are exist. 并且,当页面重新加载时,用户原始输入和文件原始值都存在。

To simplify: 为了简化:

After "file submit & read & append file values to form", user shouldn't need to fill inputs that s/he already filled. 在“提交文件并读取并附加文件值以形成表单”之后,用户不需要填写他/他已经填写的输入。 I need an idea to achieve this, different then "inserting a php line to every single input element." 我需要一个实现此目标的想法,然后不同于“将php行插入每个单独的输入元素”。

In such a situation I could recommend sending the file via AJAX and handling the response of that thereafter and then only injecting the values from the process and uploaded file when you get the response from the server. 在这种情况下,我建议您通过AJAX发送文件,然后处理该文件的响应,然后在从服务器获得响应时仅注入来自进程和上载文件的值。

Alternatively you could use localstorage or cookies to persist the information. 或者,您可以使用localstorage或cookie保留信息。 However both local storage and cookies have a defined limit on what they can store. 但是,本地存储和cookie都对存储内容有定义的限制。 Cookie can only store 4KB in total which doesn't allow much. Cookie总共只能存储4KB,这不允许太多。

Without uploading via AJAX, you could write a javascript function to find all inputs with jQuery/javascript and save their values in localstorage and on new page load to a check to see if there are any present and inject them back into the same inputs based on id/class/ etc with jQuery making sure to delete the localstorage values when done. 无需通过AJAX上传,您可以编写一个javascript函数来查找所有使用jQuery / javascript的输入,并将它们的值保存在localstorage中,并在新页面加载时检查是否存在任何值,然后根据以下信息将它们注入相同的输入中jQuery的id / class /等,确保完成后删除localstorage值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM