


在一个php中,我定义了两个表单,当第一个表单提交后,生成了第二个表单,提交第二个表单后,就取不到第一个表单的数据了,该怎么办?
表单 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#上面的代码还是出不来结果,怎么回事?
放在

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
