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