表单 php 提交 传递 数据
在一个php中,我定义了两个表单,当第一个表单提交后,生成了第二个表单,提交第二个表单后,就取不到第一个表单的数据了,该怎么办?//第一个表单
echo "";//第二个表单
var_dump($m);
?>
提交第二次后就得不到$m了,该怎么做才能将$m传递到最后呢?
本人新手,不懂得cookie、session。谢谢了!
回复讨论(解决方案)
这个最合理的做法就是用session或cookie保存前一次的提交,不懂的话就干脆以此为契机,学吧
这个最合理的做法就是用session或cookie保存前一次的提交,不懂的话就干脆以此为契机,学吧
恩,我临时学了一下,我的做法是两个表单分别放在两个php文件中,然后在第二个php中写了setcookie("m1",$m,time()+3600);
$m2=$_COOKIE["m1"];
然后我就用m2这个变量当做m的值,但是当我准备生成第三个表单的时候,怎么取到m?我觉得php跳转到下一个网页后就得不到前一个php的值了。如果用xml可以解决这种问题吗?
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
我也有这么想,但是不会隐藏变量啊,希望有代码参考一下,谢谢!
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
他这种需求我很久以前遇到过,就是做问卷调查时一道题一页??回答后才出现下一个问题,最初也是逐个做hidden传下去的,后来发觉十几道题就嫌麻烦了,用session反而简单多了
cookie我也觉得麻烦,如果用cookie就干脆做“假提交”,一次把题都发过去,用js把后面的题隐藏,逐个显示,到最后一题才一并提交
session的缺点是有时效性,需要在一定时间有动作才不会丢失值
cookie的缺点是客户端可以造假
在
间加入 php 代码foreach($_POST as $k=>$v) echo "";
怎么会麻烦呢?使用了 session 的表单页,无论怎么设置,“回退”的表现都不尽人意
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
我也有这么想,但是不会隐藏变量啊,希望有代码参考一下,谢谢!
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
他这种需求我很久以前遇到过,就是做问卷调查时一道题一页??回答后才出现下一个问题,最初也是逐个做hidden传下去的,后来发觉十几道题就嫌麻烦了,用session反而简单多了
cookie我也觉得麻烦,如果用cookie就干脆做“假提交”,一次把题都发过去,用js把后面的题隐藏,逐个显示,到最后一题才一并提交
session的缺点是有时效性,需要在一定时间有动作才不会丢失值
cookie的缺点是客户端可以造假
不是吧,我生成的表单是根据上一个表单提交数据才能用的,没有输出上限,hidden不行。
一样的,js也能根据“提交”内容生成控件,只是你不熟悉而已
实在搞不定就按#6老徐的方法写,这个思路最简单
我个人对数组相对熟悉些,所以习惯用session记录,懒得每次都对前面提交的数据再遍历一次
你可以这么的。两方式
一种方式就是分两页面:第一步提交后,到第二步的时候读取出来。
两步在一个页面:先用js隐藏第二步,ajax提交,那么再第二步也能获取第一步的值。
不要把事情弄得那么复杂
你的第二的个表单是第一个表单的处理程序创建的
那么就把第一个表单的提交以隐藏变量的形式放到第二个表单里就是了
恩,我觉得这个方法最方便,但是没有出结果,你看看我的代码好吗?
这是第二个php:
foreach($_POST as $k=>$v)
{
echo "";
}
var_dump($m);
echo "
?>
这是第三个php:
foreach($_POST as $k=>$v)
{
echo "";
}
$n;
for($i=1;$i {
$h="n".$i;
$n[]=$_POST["$h"];
}
var_dump($n);
?>
跳转到第三个php输出的是null,网址上也仅仅跟着n1、n2、n3...的值,没有出现m,怎么回事呢?
一样的,js也能根据“提交”内容生成控件,只是你不熟悉而已
实在搞不定就按#6老徐的方法写,这个思路最简单
我个人对数组相对熟悉些,所以习惯用session记录,懒得每次都对前面提交的数据再遍历一次
谢谢你!但是我用6#上面的代码还是出不来结果,怎么回事?
放在

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor
