Welcome Guest, Not a member yet? Register   Sign In
How to append params to link_to_remote
#1

[eluser]Unknown[/eluser]
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.
#2

[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">
&lt;html &gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title>
    
    USED SCRIPT -> prototype.js
&lt;/head&gt;
&lt;body&gt;
        &lt;form id="xxx" action="http://localhost/yes_promotion/test/submit" method="post"&gt;
            <p class="heading" id="heading">New User Signup</p>
            <label for="username">Username: </label>
            &lt;input type="text" name="username" value="sadsf"/&gt;
            &lt;input type="text" name="password" value="sadsf"/&gt;
        &lt;?php echo $this->ajax->link_to_remote("Login", array('url' => 'test/submit', 'update' => 'heading', 'parameters' => '', 'submit' => 'xxx')); ?&gt;
        
        &lt;!-- just for info, the submit_to_remote syntax --&gt;
        &lt;?php echo $this->ajax->submit_to_remote('submit', 'Send', array('url'=> 'test/submit', 'update' => 'heading', 'with'=>'')); ?&gt;

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

I hope this is helpful to anyone.




Theme © iAndrew 2016 - Forum software by © MyBB