Jump to content

[SOLVED] strings empty after form submit??


critical-state

Recommended Posts

Hi I am hoping that some one can give me some understanding and a soloution to a problem I am having with my $email string loosing it data after I submit the second part of a form.

This is not the actual script but a test to show what I mean about the string loosing it data.

 

I have only been studying php and HTML for a couple of weeks so if my code looks basic, please excuse.

Any feedback or comments welcome

Cheers Crit.

 

<html>

<body>

<form method="post" name="test" action="">

Enter your new email address here:

<input type ="text" size="30" name ="email">

<input type="submit" value="GO!">

</form>

<?php

$email=$_POST['email'];

$change['email']=trim((!empty($_POST['email'])) ? $_POST['email']: $_GET['email']);

if(strlen($change['email'])>3){

?>

<form method="post" action="" name="yes/no">

Yes<input type="radio" name="yes_no" value="yes">

No<input type="radio" name="yes_no" value="no">

Confirm changes:

<input type="submit" value ="Confirm">

</form>

 

<?php

}

if($_POST['yes_no']=="yes"){

echo" Your email address is: $email";// $email should be displaying the new email address. but after yes_no submit, no data is shown why? ???

echo " Why is this bloody not displaying the set varable!!! $email";  :-\

}

echo $email;

?>

 

</body>

</html> 

Link to comment
https://forums.phpfreaks.com/topic/117343-solved-strings-empty-after-form-submit/
Share on other sites

you have to put the email in another input field to be passed by the second form. You should also use some checks so you don't get errors. I have error reporting on so I get all kinds of warnings when I run your code.

 

<?php
if(!isset($_POST['email'])){
?>
<form method="post" name="test" action="">
Enter your new email address here:
<input type ="text" size="30" name ="email">
<input type="submit" value="GO!">
</form>
<?php
} else {
  if(!isset($_POST['yes_no']) && isset($_POST['email'])){
  $email=$_POST['email'];
  $change['email'] = trim((!empty($_POST['email'])) ? $_POST['email']: $_GET['email']);
    if(strlen($change['email']) > 3){
    ?>
    <form method="post" action="" name="yes/no">
    <input type=hidden name=email value="<?php echo $change['email']; ?>" />
    NEW E-Mail: <?php echo $change['email']; ?><br />
    Yes<input type="radio" name="yes_no" value="yes">
    No<input type="radio" name="yes_no" value="no">
    Confirm changes:
    <input type="submit" value ="Confirm">
    </form>
<?php
    }
  } else {
  $email = $_POST['email'];
  echo" Your email address is: $email";// $email should be displaying the new email address. but after yes_no submit, no data is shown why? Huh
  echo " Why is this bloody not displaying the set varable!!! $email";
  }
}
?>

 

Ray

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.