Jump to content

quick question #1


adv

Recommended Posts

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
https://forums.phpfreaks.com/topic/126992-quick-question-1/
Share on other sites

<?php
$s=isset($_POST['textfield']) && trim($_POST['textfield']) != ""?$_POST['textfield']:"";
$s1=isset($_POST['textfield2']) && trim($_POST['textfield2']) != ""?$_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 } ?>

Link to comment
https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656926
Share on other sites

this also seems to work

<?php
$s=trim($_POST['textfield']);
$s1=trim($_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 } ?>

Link to comment
https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656931
Share on other sites

is just the same

$s=trim($_POST['textfield']);
$s1=trim($_POST['textfield2']);

 

if the 2 fields are not empty will set errLog not to 1 and will show the first form

and same for

$s=isset($_POST['textfield']) && trim($_POST['textfield']) != ""?$_POST['textfield']:"";
$s1=isset($_POST['textfield2']) && trim($_POST['textfield2']) != ""?$_POST['textfield2']:"";

Link to comment
https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-656948
Share on other sites

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

 

you didnt understand my point

read carefully what i was saying

Link to comment
https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-657016
Share on other sites

I assume when you say

just with variables

you mean posted form fields.  You need some way of differentiating the two forms.  I usually use hidden form fields generally named action with a different value for each form so I know exactly which form the submission is coming from.

Link to comment
https://forums.phpfreaks.com/topic/126992-quick-question-1/#findComment-657182
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.