javascript - PHP: send post to div on same page instead of another page -


I have a page that is filled on the second page (index.php) on a page named login.php. Action indicates action in login.php which signifies login.php

Once I press the submit button, the page will open in a new tab (if no target is specified) , Or if target_top as the whole page is overwriting index.php) I want to open index.php, while login.php is loaded into its div, and the post data is to go to login.php which is inside the div. Is this also possible?

LOGIN.PHP

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Link href = "others.css" rel = "stylesheet" & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;? Php require_once ('funcs.php'); If ($ _ POST ['user']) & amp; blank ($ _ POST ['pass'])) {$ username = cleanInput ($ _ POST ['user']); $ Password = cleanInput ($ _post ['pass']); If (login ($ username, $ password)) {show_login_form ("invalid user name or password!"); } Else {// login ... echo "Ok boss!"; }} And {show_login_form (null); }? & Gt; & Lt; / Body & gt; & Lt; / Html & gt;  

FUNCS.PHP

  & lt; Php function cleanInput ($ data) {$ data = trim ($ data); $ Data = htmlspecialchars ($ data, ENT_QUOTES, "UTF-8"); $ Return data; } Show_login_form ($ err) {echo & lt; H4 & gt; Enter username and password: & lt; / H4 & gt; '; If (isset ($ err)) {echo "& lt; span style = 'color: red'> Error: $ err & lt; / span & gt; & lt; br & gt;"; } Echo & lt; Br> & Lt; Form method = "post" action = "login.php" & gt; Username: & lt; Br> & Lt; Input name = "user" type = "text" & gt; & Lt; Br> Password: & lt; Br> & Lt; Input name = "pass" type = "password" & gt; & Lt; Br> & Lt; Br> & Lt; Input id = "button" type = "submit" value = "login" & gt; & Lt; / Form & gt; '; }? & Gt;  

INDEX.PHP

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Dating site & lt; / Title & gt; & Lt; Link href = "site.css" rel = "stylesheet" & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;? Php require_once ("header.php"); ? & Gt; & Lt; Div id = "mainframe" class = "mainframe" & gt; & Lt ;? Php require_once ("home.php"); ? & Gt; & Lt; / Div & gt; & Lt ;? Php require_once ("footer.php"); ? & Gt; & Lt; / Body & gt; & Lt; / Html & gt;  

And to load a page in the "mainframe" div, I use this code:

  function loaded (page) {if ( Page == 1) $ ("Div # mainframe"). Load ('login.php'); } You need to use AJAX to submit your form.  

  http://jquery.malsup.com/form/#ajaxSubmit  

Download Plugin

  Function Login () {$ ('# login_form'). AjaxSubmit ({Target: '# output_login', url: './ php / login.php'}); return false; }  

Comments