?
Solved

delete form tag

Posted on 2010-03-25
4
Medium Priority
?
232 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:rgb192
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 28592436
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".
0
 
LVL 1

Author Comment

by:rgb192
ID: 28593625
could this code be done without a session start....
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 28594089
>>could this code be done without a session start....
Sure, that is what I did two posts ago on the other threads/posts, BUT you then were complaining that it reposts upon refresh.

If you still want to avoid the refresh problem, you have to remember what was previously posted, and for that you need the $_SESSION.

It's likely that your cms is using $_SESSION. If so, then it must be calling somewhere first, in which case you can just comment out the session_start(); from the code you posted above (since you need to call session_start() only ONCE and presumable the cms already called it ).
0
 
LVL 1

Author Closing Comment

by:rgb192
ID: 31707272
thanks

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

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_25522528.html?fromWizard=true
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question