[eluser]Unknown[/eluser]
[quote author="newCodeIgntor" date="1218624496"]I am trying to do a ajax username duplicate check. The code I am using is as follows:
Code:
$this->ajax->link_to_remote("check username", array('url'=> "/user/username_dpcheck/", 'loading' => "Element.show('indicator_username')",'complete' => "Element.hide('indicator_username'),alert('dd')",'update' => 'username_check'));
What I am trying to do is to append a parameter behind url, which is /user/username_dpcheck/ and make it look like
/user/username_dpcheck/parameter. Therefore, when I click on "check username", the action URL will be
/user/username_dpcheck/parameter
The parameter is the value of an input field, which I try to get by using getElementById('field').value
I am wondering whether there is a good way to accomplish this.
Another question is when I try to use observe_field, it gives me following error message
A PHP Error was encountered
Severity: Notice
Message: Undefined index: function
Filename: libraries/Ajax.php
Line Number: 247
Any help will be very much appreciated. Thanks a lot for all your quick response and help to my previous questions.[/quote]
Hi, I got it!
I know this solution won't help you "newCodeIgntor", but maybe others (like me) can profit from this post.
I just read the Ajax.php file and found the right Syntax to use!
Code:
<?php echo $this->ajax->link_to_remote("Login", array('url' => 'test/submit', 'update' => 'heading', 'parameters' => '', 'submit' => 'xxx')); ?>
the important part is
'parameters' => '', 'submit' => 'xxx'.
'parameters' => '' is simply needed (i don't know why, but the Ajax.php checks if existance)
'submit' => 'xxx': xxx stands for the id of the form-tag (every form-element with a name attribute inside the form-tags will be send as post-parameters)
here my complete files:
Controller: test.php
Code:
<?php
class Test extends Controller {
function index() {
$this->load->library('ajax');
$this->load->view('test');
}
function submit() {
$xy = $this->input->post('username');
$update = $xy;
echo $update;
}
}
View: test.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title></title>
USED SCRIPT -> prototype.js
</head>
<body>
<form id="xxx" action="http://localhost/yes_promotion/test/submit" method="post">
<p class="heading" id="heading">New User Signup</p>
<label for="username">Username: </label>
<input type="text" name="username" value="sadsf"/>
<input type="text" name="password" value="sadsf"/>
<?php echo $this->ajax->link_to_remote("Login", array('url' => 'test/submit', 'update' => 'heading', 'parameters' => '', 'submit' => 'xxx')); ?>
<!-- just for info, the submit_to_remote syntax -->
<?php echo $this->ajax->submit_to_remote('submit', 'Send', array('url'=> 'test/submit', 'update' => 'heading', 'with'=>'')); ?>
</form>
</body>
</html>
I hope this is helpful to anyone.