Jump to content

Recommended Posts

Posted (edited)

Boas pessoal.

mais um post mais uma dúvida.

Qual a forma de manter o valor de uma variável por mais vzes que a página faça refresh?

<form action="" enctype="multipart/form-data" method="POST" name="pesqa" id="pesqa" onsubmit="return verifica(this)">
<table align="center" width="100%">
<tr>
 <td colspan="4" align="center" class="style1">
	Ordenar por:<input type="hidden" name="texto2" value="<?php echo $_POST['texto']  ?>" />
	</td>
			</tr>
	<tr>
	 <td class="style30" valign="top" align="center">
	 Descrição<input type="image" src="images/arrow-down.png" value="descdesc" name="descdesc" alt="descdesc" width="25" height="25"/><input type="image" src="images/arrow-up.png" name="descasc" value="descasc" alt="descasc" width="25" height="25"/>
			</td>
	 <td class="style30" valign="top" align="center">
 Preço<input type="image" src="images/arrow-down.png" name="precodesc" value="precodesc" alt="precodesc" width="25" height="25"/><input type="image" src="images/arrow-up.png" name="precoasc" value="precoasc" alt="precoasc" width="25" height="25"/>
			</td>
			<td class="style30" valign="top" align="center">
 Referência<input type="image" src="images/arrow-down.png" name="referdesc" value="referdesc" alt="referdesc" width="25" height="25"/><input type="image" src="images/arrow-up.png" value="referasc" alt="referasc" name="referasc" width="25" height="25"/>
			</td>
			<td class="style30" valign="top" align="center">
 Marca<input type="image" src="images/arrow-down.png" name="marcadesc" value="marcadesc" alt="marcadesc" width="25" height="25"/><input type="image" src="images/arrow-up.png" value="marcaasc" alt="marcaasc" name="marcaasc" width="25" height="25"/>
	  </td>
</tr>
</table>
</form>

basicamente queria que a o POST deste formulário se mantivesse quando a página fizesse refresh várias vezes

( a página faz refresh sempre que carrego num dos input dos formulários que é para ordenar a pesquisa).

eu vou buscar esta varável com

$texto2=$_POST['texto2'];

a primeira vez funciona.

mas a segunda vez que carrego noutro input ele ja nao faz nada.

há alguma forma de manter a variavel $texto2 com o mesmo valor??

Edited by JFernandesVR
Posted

"Que inquieto desejo vos tortura, Seres elementares, força obscura? Em volta de que ideia gravitais?" >> Anthero de Quental

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Linuxando.com | ...

Posted

Vê a documentação com atenção.

O session_start(); tem de ser chamado antes de qualquer output para o browser. Um output pode ser um echo mas também um notice ou error ou...

Experimenta fazer echo à $_SESSION['texto2'] para veres se está definida.

Também me parece que da primeira vez que abres o formulário não terás definida a variável $_POST['texto2'], correto? Ou seja, tens de verificar se o POST está definido e se nao, é porque é a primeira vez que o user está a abrir o formulário.

"Que inquieto desejo vos tortura, Seres elementares, força obscura? Em volta de que ideia gravitais?" >> Anthero de Quental

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Linuxando.com | ...

Posted (edited)

o formulário só aparece depois de se fazr a pesquisa.

só depois disso é que o formulário aparece.

então eu fiz-lhe um POST para estar já definido coo valor a pesquisar novamente. basicamente a 2ª pesquisa é ordenar os resultados e dá.

só quando é para escolher outro filtro de ordenação esse valor POST ja nao aparece. ou seja so do 3º para a frente é que nao aparece.

entao em vez de POST tenho de POR SESSION?

$_SESSION['texto2']=$_POST['texto']; -> no inicio

$texto2=$_SESSION['texto2'];

<input type="hidden" name="texto2" value="<?php echo $texto2 ?>" />

mas nao funca

Edited by JFernandesVR
Posted (edited)

aparece-me isto

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

Edited by JFernandesVR
Posted

Please be advised that the session extension does not consider global variables as a source of data,

Muda o nome da tua variável e vê se permanece o erro:

$_SESSION['texto2']=$_POST['texto'];

$_SESSION['filtro']=$_POST['texto'];
$texto2=$_SESSION['filtro'];

"Que inquieto desejo vos tortura, Seres elementares, força obscura? Em volta de que ideia gravitais?" >> Anthero de Quental

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Linuxando.com | ...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.