critical-state Posted July 30, 2008 Share Posted July 30, 2008 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 More sharing options...
trq Posted July 30, 2008 Share Posted July 30, 2008 You have two forms. One of which sends the radio buttons 'yes_no' the other of which sends your text fileld 'email'. Both forms are not submitted together. Link to comment https://forums.phpfreaks.com/topic/117343-solved-strings-empty-after-form-submit/#findComment-603605 Share on other sites More sharing options...
craygo Posted July 30, 2008 Share Posted July 30, 2008 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 Link to comment https://forums.phpfreaks.com/topic/117343-solved-strings-empty-after-form-submit/#findComment-603608 Share on other sites More sharing options...
critical-state Posted July 30, 2008 Author Share Posted July 30, 2008 Cheers craygo I have switched my error checking on and yes there are all sorts of issues with my original code. Thanks for the tip and the code Andy Link to comment https://forums.phpfreaks.com/topic/117343-solved-strings-empty-after-form-submit/#findComment-603669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.