Welcome Guest, Not a member yet? Register   Sign In
Input class and JQuery
#1

[eluser]minerbog[/eluser]
Hi Peeps,

Come up against a problem today that has taken me ages to find let alone workout!

Basically I have a JQuery model form for login, and then use JQuery .submit() function to submit the form (code below). However, when I then use the input->post function to get the posted data it always returns false as if no data has been posted.

Please please help if you have come across this becuase I really can't see why??

View File:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;!--Head Section--&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
&lt;link rel="stylesheet" href="http://localhost/accounting.site/style.css" /&gt;
&lt;link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/blitzer/jquery-ui.css" /&gt;

&lt;link rel="icon" href="http://localhost/my.site/img/icons/favicon.ico" type="image/x-icon"/&gt;
&lt;link rel="shortcut icon" href="http://localhost/my.site/img/icons/favicon.ico" type="image/x-icon" /&gt;

[removed][removed]
[removed][removed]

&lt;/head&gt;
&lt;body&gt;
&lt;style type="text/css"&gt;
#container {
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
margin: 50px;
}

h3 {
text-align: center;
padding: 10px;
font-size: 14px;
}

p {
margin: 12px;
}
&lt;/style&gt;

[removed]
$(document).ready(
function() {
$( "#login-dialog" ).dialog({
    draggable: false,
    resizable : false,
    modal : true,
    buttons :
     { "Login" : function() { $('#login-form').submit(); } }
    });
}
);
[removed]

&lt;form id="login-form" method="post" action="login/now"&gt;
<div id="login-dialog" title="Login">
<p>Username:&lt;input name="user" type="text" /&gt;&lt;/p
><p>Password:&lt;input name="pass" type="password" /&gt;&lt;/p>
</div>
&lt;/form&gt;


<noscript>
<div id="container">
<h3>Ajax and Javascript are required to run this application. Please see the <a href="#">FAQ</a> for more details as to why.</h3>
</div>
</noscript>

&lt;/body&gt;
&lt;/html&gt;

Controller:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {


public function index()
{
  $this->load->view('v_login');
}

public function now()
{
  $username = $this->input->post('user');
  if ($username === false)
  {
   echo 'No Data';
  }else{
  echo $username;
  }
}
}

/* End of file */
/* Location: ./application/controllers/login.php */
#2

[eluser]vitoco[/eluser]
I think the problem is that the div that you're showing in the modal it's inside the form, so the form gets empty..

WRONG WAY :
Code:
&lt;form id="login-form" method="post" action="login/now"&gt;
<div id="login-dialog" title="Login">
<p>Username:&lt;input name="user" type="text" /&gt;&lt;/p
><p>Password:&lt;input name="pass" type="password" /&gt;&lt;/p>
</div>
&lt;/form&gt;

So put the div wrapping the form...

RIGHT WAY :
Code:
<div id="login-dialog" title="Login">
&lt;form id="login-form" method="post" action="login/now"&gt;
<p>Username:&lt;input name="user" type="text" /&gt;&lt;/p
><p>Password:&lt;input name="pass" type="password" /&gt;&lt;/p>
&lt;/form&gt;
</div>

Saludos
#3

[eluser]CroNiX[/eluser]
Use firebug and see what data is actually getting transmitted and if it's going to the URL it's supposed to. I have a feeling jQuery isn't sending it to the correct place because you are using "login/now" as the action, which is a relative path. Minimally it should be "/login/now", with an initial slash, but the full path would be best. If you haven't removed "index.php" from the url using htaccess, then that must also be included in the url, like "/index.php/login/now". Make sure it is actually sending the form variables via POST (again, firebug!).




Theme © iAndrew 2016 - Forum software by © MyBB