Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

delete form tag

I made the code shorter by deleting the <html> and <head> <body> tags


now I want to delete the form tag
because I want to put this on a content management system that has a form and a jquery table sorter and it is not working on my cms


is this possible
<?php  
ini_set('error_reporting', E_ALL); 
error_reporting(E_ALL); 
session_start(); 
         if( isset($_POST) && !empty($_POST)) 
          { 
                        if(isset($_SESSION['prev']) && $_SESSION['prev']==serialize($_POST)) 
                        { 
                                echo "Data already processed!"; 
                                exit; 
                        } 
                $msg=""; 
                $msg="You sent " . print_r($_POST,true); 
                 
                //here you can try to save it to the db: 
                //mysql_connect("localhost","username","password") or die($msg."\nunable to connect to server: \n".mysql_error()); 
                //mysql_select_db("dbname") or die($msg."\nUnable to select db: \n" . mysql_error()); 
           
                //$FieldName=mysql_real_escape_string($_POST['FieldName']); 
           
                //$sql="INSERT INTO tableName(fieldName) VALUES('{$FieldName}')"; 
           
                //mysql_query($sql) or die($msg."\nUnable to execute query: \n$sql\n".mysql_error()); 
                         $_SESSION['prev']=serialize($_POST); 
                echo $msg."\nData proccessed successfully"; 
          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); 
//NOTE: ADDED a  return false; 
                                                          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='FieldName' name='FieldName' value=''/></div> 
                          <div><input type='submit' name='Submitter' value='Submit'/></div> 
                  </form>

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image

it sounds like you are "pasting" that code within the body of your "template". It will not work because the session_start() cannot be called after you have sent output to the browser. You need to call session_start() at the beginning of your "template".
Avatar of rgb192

ASKER

could this code be done without a session start....
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks

I have the same question with an earlier version of your code that I removed html,head,body tags without the session

https://www.experts-exchange.com/questions/25522528/code-without-session-want-to-delete-form-tags.html?fromWizard=true