I want to keep on asking for textbox and checkbox and display session.

I want to keep on asking for textbox and checkbox and display session.


<?php
session_start();
ini_set('error_reporting', E_ALL);  
error_reporting(E_ALL);
print_r($_SESSION);  
  
         if( isset($_POST) && !empty($_POST))  
          { 
                $_SESSION['email'] = $_POST['email'];
                $_SESSION['agree'] = $_POST['agree'];
                
                        echo "Email: " .$_POST['email'];                         
                        echo "Agree: " . ( (isset($_POST['agree']) && $_POST['agree']=='Yes') ? 'Yes':'No');                     
          exit;  
          }  
          ?>  
 
 
                          <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>  
                          <script>  
                          $(function(){  
                                  $("#FieldName").bind('change',function(){  
                                          var opts={  
                                                                  url: this.form.action  
                                                                  ,type: this.form.method  
                                                                  ,data:{ }  
                                                                  ,success:processResult  
                                                          };  
                                                          opts.data[this.name]=encodeURIComponent(this.value);  
                                          $.ajax(opts);  
 
                                                          return false;  
                                  });  
                          });  
                            
                          function processResult(data, textStatus){  
                                  alert(data);  
                          }  
                          </script>  
                  <form id='theForm' action='<?php $_SERVER["PHP_SELF"] ?>' method='post'>  
                          <div>Email: <input type='text' id='email' name='email' value=''/></div>  
                                         <div><input type='checkbox' id='agree' name='agree' value='Yes'/>Yes, I agree to the site rules!</div>  
                          <div><input type='submit' name='Submitter' value='Submit'/></div>  
                  </form>

Open in new window

LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kumaranmcaCommented:
Try the following code...
<?php
session_start();
ini_set('error_reporting', E_ALL);  
error_reporting(E_ALL);
print_r($_SESSION);  
  
         if( isset($_POST) && !empty($_POST))  
          { 
                $_SESSION['email'] = $_POST['email'];
                $_SESSION['agree'] = $_POST['agree'];
                
                        echo "Email: " .$_POST['email'];                         
                        echo "Agree: " . ( (isset($_POST['agree']) && $_POST['agree']=='Yes') ? 'Yes':'No');                     
          exit;  
          }  
          ?>  
 
 
                          <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>  
                          <script>  
                          $(function(){  
                                  $("#FieldName").bind('change',function(){  
                                          var opts={  
                                                                  url: this.form.action  
                                                                  ,type: this.form.method  
                                                                  ,data:{ }  
                                                                  ,success:processResult  
                                                          };  
                                                          opts.data[this.name]=encodeURIComponent(this.value);  
                                          $.ajax(opts);  
 
                                                          return false;  
                                  });  
                          });  
                            
                          function processResult(data, textStatus){  
                                  alert(data);  
                          }  
                          </script>  
                  <form id='theForm' action='<?php $_SERVER["PHP_SELF"] ?>' method='post'>  
                          <div>Email: <input type='text' id='email' name='email' value='<?php if($_SESSION['email']!='') echo $_SESSION['email']; ?>' /></div>  
                                         <div><input type='checkbox' id='agree' name='agree' value='Yes' <?php if($_SESSION['agree']=='Yes') echo 'checked'; ?>/>Yes, I agree to the site rules!</div>  
                          <div><input type='submit' name='Submitter' value='Submit'/></div>  
                  </form>

Open in new window

0
kumaranmcaCommented:
Session value set in textbox and checkbox...

<input type='text' id='email' name='email' value='<?php if($_SESSION['email']!='') echo $_SESSION['email']; ?>' /></div>  
                                         <div><input type='checkbox' id='agree' name='agree' value='Yes' <?php if($_SESSION['agree']=='Yes') echo 'checked'; ?>/>Yes, I agree to the site rules!</div>  
0
rgb192Author Commented:
ran code and cant get textbox and checkbox to re-appear after submit
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

kumaranmcaCommented:
Sorry.  Try the following code...its solve the issue
<?php
session_start();
ini_set('error_reporting', E_ALL);  
error_reporting(E_ALL);
         if( isset($_POST) && !empty($_POST))  
          { 
                $_SESSION['email'] = $_POST['email'];
				if(isset($_POST['agree'])){
	                $_SESSION['agree'] = $_POST['agree'];
				}else{
	                $_SESSION['agree']='';
				}
                
                        echo "Email: " .$_POST['email'];                         
                        echo "Agree: " . ( (isset($_POST['agree']) && $_POST['agree']=='Yes') ? 'Yes':'No');                     
          }  
          ?>  
 
                  <form id='theForm' action='<?php $_SERVER["PHP_SELF"] ?>' method='post'>  
                          <div>Email: <input type='text' id='email' name='email' value='<?php if($_SESSION['email']!='') echo $_SESSION['email']; ?>' /></div>  
                                         <div><input type='checkbox' id='agree' name='agree' value='Yes' 
										 <?php 
										 if(isset($_SESSION['agree']) && $_SESSION['agree']!='') {
										 echo 'checked'; 
										 }
										 ?>/>Yes, I agree to the site rules!</div>  
                          <div><input type='submit' name='Submitter' value='Submit'/></div>  
                  </form>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192Author Commented:
thanks
0
kumaranmcaCommented:
Thank rgb...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.