Jump to content

[SOLVED] quick problem


adv

Recommended Posts

<?php 
if(isset($_POST['sub'])){
$ss=$_POST['test'];
$ss1=$_POST['test1'];
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form1">
<input type="hidden" name="first" value="<?php echo $ss; ?>" />
<input type="hidden" name="second" value="<?php echo $ss1; ?> " />

<br /><br />
<input type="text" name="test" value="" />
<input type="text" name="test1" value="" />
<br /><br />

<input type="submit" name="sub" value="login" />
</form>

 

 

 

the problem is that when i submit the page it shows like this

Array
(
    [first] => 
    [second] =>  
    [test] => asdasdas
    [test1] => adasdassa
    [sub] => login
)

and when i submit with empty values in the 2 inputs it shows like this

Array
(
    [first] => asdasdas
    [second] => adasdassa 
    [test] => 
    [test1] => 
    [sub] => login
)

 

why doesnt when i submit the page first time shows all the values

like this

 

Array
(
    [first] => asdasdas
    [second] => adasdassa 
    [test] => asdasdas
    [test1] => adasdassa
    [sub] => login
)

 

 

Link to comment
Share on other sites

Of course it works exactly how you programmed it. When the submitted values are posted back to the script, you are applying the values of test and test1 to variables, but that doesn't mean that they are in the post array. They finally make it to the post array when you submit the second time, because they were values in the form only on the second submission.

 

Try this:

 

<?php 
if(isset($_POST['sub'])){
$ss=$_POST['test'];
$_POST['first']=$_POST['test'];
$ss1=$_POST['test1'];
$_POST['second']=$_POST['test1'];
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form1">
<input type="hidden" name="first" value="<?php echo $ss; ?>" />
<input type="hidden" name="second" value="<?php echo $ss1; ?> " />

<br /><br />
<input type="text" name="test" value="" />
<input type="text" name="test1" value="" />
<br /><br />

<input type="submit" name="sub" value="login" />
</form>

Link to comment
Share on other sites

i dont think there is a need to open another tread ...

the problem is this  :

<?php
$s=$_POST['textfiled'];
$s1=$_POST['textfield2'];
if (isset($_POST['button'])) {
if (empty($s)||empty($s1)) {
	$errLog=1;	
}
}

?>
<?php if ($errLog !=1) { ?> 
<form name="firstForm" method="post" action="">
  <p>
    <input type="text" name="textfield" id="textfield">
</p>
  <p>
    <label>
    <input type="text" name="textfield2" id="textfield2">
    </label>
</p>
  <p>
    <input type="submit" name="button" id="button" value="Submit">
  </p>
</form>
<p> </p>

<?php } else { ?>
<form name="secondForm" method="post" action="">
  <p>
    <input type="text" name="textfield" id="textfield">
</p>
  <p>
    <label>
    <input type="text" name="textfield2" id="textfield2">
    </label>
</p>
  <p>
    <input type="text" name="textfield3" id="textfield3">
  </p>
  <p>
    <input type="submit" name="button" id="button" value="Submit">
  </p>
</form>
<p> </p>
<?php } ?>

 

the problem is when i submit the page and is empty one of the values is shows the second form

but if i submit the second form and the inputs are not empty it redirects me to the first form

i`ve tried with $_SESSION and it works ... but i wanna know is there is a way just with variables

 

when i submit the second form and the values are not empty i just wanna show lets say

thanks in advance

echo 'good';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.