AJAX forms with Dojo

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

AJAX forms with Dojo

by Kyle Spraggs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Anyone care to shed some light on just how to use AJAX forms properly? I
can create and submit the form using AJAX just fine it's when I attempt
to load the response that things get wonky. Specifically, I can't seem
to get the returned data to parse properly.

Incoming code:

<?php $this->dojo()->onLoadCaptureStart();?>
function signupCall() {
     dojo.connect(dijit.byId('signupform'), 'onSubmit', function(e) {
         e.preventDefault();

         dojo.xhrPost({
             form: dojo.byId("signupform"),
             url: '<?=$this->url(array('action' => 'signup',
'controller' => 'events', 'module' => 'user'), 'default',
true);?>?format=html',
             handleAs: "text",
             load: function(data) {
                 dojo.byId('signupDialog').innerHTML = data;
             },
             error: function(error) {
                 dojo.byId('errorMsg').innerHTML = error;
                 dijit.byId('errorDlg').show();
             }
         });
     });
}
<?php $this->dojo()->onLoadCaptureEnd();?>

<button id="signup-button" dojoType="dijit.form.Button">
<script type="dojo/event" event="onClick">
         dijit.byId('signupDialog').show();
</script>

<img src=/images/icons/18/signup.png" alt="Signup" /> Signup
</button>
<div id="signupDialog" dojoType="dojox.widget.Dialog" dimensions="[600,
400]" draggable="false" sizeDuration="120" sizeMethod="combine">
<div dojoType="dijit.layout.ContentPane">
         // Zend Framework, renders a dojo form with two
FilteringSelects, a TextArea, and a submit button
<?=$this->action('signup', 'events', 'user');?>
</div>
</div>


Again, everything works fine but parsing the data from the AJAX call. I
did try using dojo.parser.parse(dojo.byId('signupform')); which
attempted to do it's job but I received the error saying the id was
already registered. Then, I tried putting everything in a ContentPane as
shown above and I couldn't get that to work either. Any help would be
greatly appreciated.

Thanks,

--
Kyle Spraggs (SpiffyJr)
http://www.spiffyjr.me

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: AJAX forms with Dojo

by Nicola Rizzo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In your load callback you wrote dojo.byId("signupDialog") instead of
dijit.byId("signupDialog"); use
dijit.byId("signupDialog").attr("content", data) instead of innerHTML.
Regards,
    Nicola

On Wed, Nov 4, 2009 at 8:55 AM, Kyle Spraggs <theman@...> wrote:

> Anyone care to shed some light on just how to use AJAX forms properly? I
> can create and submit the form using AJAX just fine it's when I attempt
> to load the response that things get wonky. Specifically, I can't seem
> to get the returned data to parse properly.
>
> Incoming code:
>
> <?php $this->dojo()->onLoadCaptureStart();?>
> function signupCall() {
>     dojo.connect(dijit.byId('signupform'), 'onSubmit', function(e) {
>         e.preventDefault();
>
>         dojo.xhrPost({
>             form: dojo.byId("signupform"),
>             url: '<?=$this->url(array('action' => 'signup',
> 'controller' => 'events', 'module' => 'user'), 'default',
> true);?>?format=html',
>             handleAs: "text",
>             load: function(data) {
>                 dojo.byId('signupDialog').innerHTML = data;
>             },
>             error: function(error) {
>                 dojo.byId('errorMsg').innerHTML = error;
>                 dijit.byId('errorDlg').show();
>             }
>         });
>     });
> }
> <?php $this->dojo()->onLoadCaptureEnd();?>
>
> <button id="signup-button" dojoType="dijit.form.Button">
> <script type="dojo/event" event="onClick">
>         dijit.byId('signupDialog').show();
> </script>
>
> <img src=/images/icons/18/signup.png" alt="Signup" /> Signup
> </button>
> <div id="signupDialog" dojoType="dojox.widget.Dialog" dimensions="[600,
> 400]" draggable="false" sizeDuration="120" sizeMethod="combine">
> <div dojoType="dijit.layout.ContentPane">
>         // Zend Framework, renders a dojo form with two
> FilteringSelects, a TextArea, and a submit button
> <?=$this->action('signup', 'events', 'user');?>
> </div>
> </div>
>
>
> Again, everything works fine but parsing the data from the AJAX call. I
> did try using dojo.parser.parse(dojo.byId('signupform')); which
> attempted to do it's job but I received the error saying the id was
> already registered. Then, I tried putting everything in a ContentPane as
> shown above and I couldn't get that to work either. Any help would be
> greatly appreciated.
>
> Thanks,
>
> --
> Kyle Spraggs (SpiffyJr)
> http://www.spiffyjr.me
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: AJAX forms with Dojo

by Kyle Spraggs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11/4/2009 2:35 AM, Nicola Rizzo wrote:

> In your load callback you wrote dojo.byId("signupDialog") instead of
> dijit.byId("signupDialog"); use
> dijit.byId("signupDialog").attr("content", data) instead of innerHTML.
> Regards,
>      Nicola
>
> On Wed, Nov 4, 2009 at 8:55 AM, Kyle Spraggs<theman@...>  wrote:
>    
>> Anyone care to shed some light on just how to use AJAX forms properly? I
>> can create and submit the form using AJAX just fine it's when I attempt
>> to load the response that things get wonky. Specifically, I can't seem
>> to get the returned data to parse properly.
>>
>> Incoming code:
>>
>> <?php $this->dojo()->onLoadCaptureStart();?>
>> function signupCall() {
>>      dojo.connect(dijit.byId('signupform'), 'onSubmit', function(e) {
>>          e.preventDefault();
>>
>>          dojo.xhrPost({
>>              form: dojo.byId("signupform"),
>>              url: '<?=$this->url(array('action' =>  'signup',
>> 'controller' =>  'events', 'module' =>  'user'), 'default',
>> true);?>?format=html',
>>              handleAs: "text",
>>              load: function(data) {
>>                  dojo.byId('signupDialog').innerHTML = data;
>>              },
>>              error: function(error) {
>>                  dojo.byId('errorMsg').innerHTML = error;
>>                  dijit.byId('errorDlg').show();
>>              }
>>          });
>>      });
>> }
>> <?php $this->dojo()->onLoadCaptureEnd();?>
>>
>> <button id="signup-button" dojoType="dijit.form.Button">
>> <script type="dojo/event" event="onClick">
>>          dijit.byId('signupDialog').show();
>> </script>
>>
>> <img src=/images/icons/18/signup.png" alt="Signup" />  Signup
>> </button>
>> <div id="signupDialog" dojoType="dojox.widget.Dialog" dimensions="[600,
>> 400]" draggable="false" sizeDuration="120" sizeMethod="combine">
>> <div dojoType="dijit.layout.ContentPane">
>>          // Zend Framework, renders a dojo form with two
>> FilteringSelects, a TextArea, and a submit button
>> <?=$this->action('signup', 'events', 'user');?>
>> </div>
>> </div>
>>
>>
>> Again, everything works fine but parsing the data from the AJAX call. I
>> did try using dojo.parser.parse(dojo.byId('signupform')); which
>> attempted to do it's job but I received the error saying the id was
>> already registered. Then, I tried putting everything in a ContentPane as
>> shown above and I couldn't get that to work either. Any help would be
>> greatly appreciated.
>>
>> Thanks,
>>
>> --
>> Kyle Spraggs (SpiffyJr)
>> http://www.spiffyjr.me
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>      
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>    
Ah, amazing! So, do I have to reconnect the event to the form everytime?
I'm assuming so because the xhrPost never fires after the initial submit.

--
Kyle Spraggs (SpiffyJr)
http://www.spiffyjr.me

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: AJAX forms with Dojo

by Karl Tiedt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If the form is replaced by the dialog content updating, yes... also note if your form is fully setup in markup (has action defined and what not) you only need to do form: 'formId' in your XHR args
-Karl Tiedt


On Wed, Nov 4, 2009 at 08:14, Kyle Spraggs <theman@...> wrote:
On 11/4/2009 2:35 AM, Nicola Rizzo wrote:
> In your load callback you wrote dojo.byId("signupDialog") instead of
> dijit.byId("signupDialog"); use
> dijit.byId("signupDialog").attr("content", data) instead of innerHTML.
> Regards,
>      Nicola
>
> On Wed, Nov 4, 2009 at 8:55 AM, Kyle Spraggs<theman@...>  wrote:
>
>> Anyone care to shed some light on just how to use AJAX forms properly? I
>> can create and submit the form using AJAX just fine it's when I attempt
>> to load the response that things get wonky. Specifically, I can't seem
>> to get the returned data to parse properly.
>>
>> Incoming code:
>>
>> <?php $this->dojo()->onLoadCaptureStart();?>
>> function signupCall() {
>>      dojo.connect(dijit.byId('signupform'), 'onSubmit', function(e) {
>>          e.preventDefault();
>>
>>          dojo.xhrPost({
>>              form: dojo.byId("signupform"),
>>              url: '<?=$this->url(array('action' =>  'signup',
>> 'controller' =>  'events', 'module' =>  'user'), 'default',
>> true);?>?format=html',
>>              handleAs: "text",
>>              load: function(data) {
>>                  dojo.byId('signupDialog').innerHTML = data;
>>              },
>>              error: function(error) {
>>                  dojo.byId('errorMsg').innerHTML = error;
>>                  dijit.byId('errorDlg').show();
>>              }
>>          });
>>      });
>> }
>> <?php $this->dojo()->onLoadCaptureEnd();?>
>>
>> <button id="signup-button" dojoType="dijit.form.Button">
>> <script type="dojo/event" event="onClick">
>>          dijit.byId('signupDialog').show();
>> </script>
>>
>> <img src=/images/icons/18/signup.png" alt="Signup" />  Signup
>> </button>
>> <div id="signupDialog" dojoType="dojox.widget.Dialog" dimensions="[600,
>> 400]" draggable="false" sizeDuration="120" sizeMethod="combine">
>> <div dojoType="dijit.layout.ContentPane">
>>          // Zend Framework, renders a dojo form with two
>> FilteringSelects, a TextArea, and a submit button
>> <?=$this->action('signup', 'events', 'user');?>
>> </div>
>> </div>
>>
>>
>> Again, everything works fine but parsing the data from the AJAX call. I
>> did try using dojo.parser.parse(dojo.byId('signupform')); which
>> attempted to do it's job but I received the error saying the id was
>> already registered. Then, I tried putting everything in a ContentPane as
>> shown above and I couldn't get that to work either. Any help would be
>> greatly appreciated.
>>
>> Thanks,
>>
>> --
>> Kyle Spraggs (SpiffyJr)
>> http://www.spiffyjr.me
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
Ah, amazing! So, do I have to reconnect the event to the form everytime?
I'm assuming so because the xhrPost never fires after the initial submit.

--


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: AJAX forms with Dojo

by Kyle Spraggs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11/4/2009 9:18 AM, Karl Tiedt wrote:
If the form is replaced by the dialog content updating, yes... also note if your form is fully setup in markup (has action defined and what not) you only need to do form: 'formId' in your XHR args
-Karl Tiedt


On Wed, Nov 4, 2009 at 08:14, Kyle Spraggs <theman@...> wrote:
On 11/4/2009 2:35 AM, Nicola Rizzo wrote:
> In your load callback you wrote dojo.byId("signupDialog") instead of
> dijit.byId("signupDialog"); use
> dijit.byId("signupDialog").attr("content", data) instead of innerHTML.
> Regards,
>      Nicola
>
> On Wed, Nov 4, 2009 at 8:55 AM, Kyle Spraggs<theman@...>  wrote:
>
>> Anyone care to shed some light on just how to use AJAX forms properly? I
>> can create and submit the form using AJAX just fine it's when I attempt
>> to load the response that things get wonky. Specifically, I can't seem
>> to get the returned data to parse properly.
>>
>> Incoming code:
>>
>> <?php $this->dojo()->onLoadCaptureStart();?>
>> function signupCall() {
>>      dojo.connect(dijit.byId('signupform'), 'onSubmit', function(e) {
>>          e.preventDefault();
>>
>>          dojo.xhrPost({
>>              form: dojo.byId("signupform"),
>>              url: '<?=$this->url(array('action' =>  'signup',
>> 'controller' =>  'events', 'module' =>  'user'), 'default',
>> true);?>?format=html',
>>              handleAs: "text",
>>              load: function(data) {
>>                  dojo.byId('signupDialog').innerHTML = data;
>>              },
>>              error: function(error) {
>>                  dojo.byId('errorMsg').innerHTML = error;
>>                  dijit.byId('errorDlg').show();
>>              }
>>          });
>>      });
>> }
>> <?php $this->dojo()->onLoadCaptureEnd();?>
>>
>> <button id="signup-button" dojoType="dijit.form.Button">
>> <script type="dojo/event" event="onClick">
>>          dijit.byId('signupDialog').show();
>> </script>
>>
>> <img src=/images/icons/18/signup.png" alt="Signup" />  Signup
>> </button>
>> <div id="signupDialog" dojoType="dojox.widget.Dialog" dimensions="[600,
>> 400]" draggable="false" sizeDuration="120" sizeMethod="combine">
>> <div dojoType="dijit.layout.ContentPane">
>>          // Zend Framework, renders a dojo form with two
>> FilteringSelects, a TextArea, and a submit button
>> <?=$this->action('signup', 'events', 'user');?>
>> </div>
>> </div>
>>
>>
>> Again, everything works fine but parsing the data from the AJAX call. I
>> did try using dojo.parser.parse(dojo.byId('signupform')); which
>> attempted to do it's job but I received the error saying the id was
>> already registered. Then, I tried putting everything in a ContentPane as
>> shown above and I couldn't get that to work either. Any help would be
>> greatly appreciated.
>>
>> Thanks,
>>
>> --
>> Kyle Spraggs (SpiffyJr)
>> http://www.spiffyjr.me
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
Ah, amazing! So, do I have to reconnect the event to the form everytime?
I'm assuming so because the xhrPost never fires after the initial submit.

--

_______________________________________________ FAQ: http://dojotoolkit.org/support/faq Book: http://docs.dojocampus.org Dojo-interest@... http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
Thank you. I was aware of the FormId but I'm not setting the action until runtime. Thanks for the tips.

-- 
Kyle Spraggs (SpiffyJr)
http://www.spiffyjr.me

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Ajax Dojo Form Validation

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello everyone,

I am using a form widget to send data to my server. I have validated the single fields of the form, but still i want to do a second validation when the form is submitted just incase someone tries to submit without filling any of the fields.
This means i have to capture the onSubmit event, stop its propagation and then do my second validation. The idea here is to use dojo.every and stop at the first occurance of invalidity and the "invalidmessage" message attached to my  ValidationTextbox will be showed. If everything is fine, i want to xhrPost the message to the server and write it to the database and send a success  or an error message back which should be displayed to the user.

I have understood the theory but my implementation does not work. When i try to submit without filling anthing, nothing happens. But when i fill out the form and click submit, the page with the form simply reloads and nothing is sent to the server. What am i doing wrong? secondly where ist it best to attach the url? as a parameter to xhrPost of at the "action" artribute of the form. I need help with this stuff. I have included bits of my code. Please HELP

JAVASCRIPT/DOJO

// The function processForm will be used to process form before submitting form data to server
function processForm(){
   
    var button = dijit.byId("submitButton");

    dojo.connect(button, "onSubmit", function(evt) {
        //Stop the submit event and check field forms one after the othef
        evt.preventDefault();
        evt.stopPropagation();
       
        var mySignupForm = dijit.byId("mySignupForm");

        var invalidEntry = null;
        dojo.every(mySignupForm.getDescendants(), function(item) {
            invalidEntry = item;
            return !item.isValid || item.isValid();
        });
        if (invalidEntry != null) {
            // set focus to first field with an error
            invalidEntry.focus();
        } else {
            sendForm();
        }

});
}
function sendForm(){
    var mySignupForm = dijit.byId("mySignupForm");
    var query = dojo.formToQuery("mySignupForm");
    var xhrArgs = {
            url: "../../server/validation/saveUserData.php",
            form: dijit.byId("mySignupForm"),
            postData: query,
            handleAs: "json",
            load: function(response) {
                dojo.byId("mainpane").innerHTML = response;
            },
            error: function(error) {
                dojo.byId("mainpane").innerHTML = response;
            }
        };
        var deferred = dojo.xhrPost(xhrArgs);
}

Portions of HTML

Here i define my form widget

<form  id="mySignupForm"  name="userInfo" method ="post"
            dojoType="dijit.form.Form"/>
            <fieldset>

and here my button

<button class="formInputButton" type="submit" name="signupButton" id="signupButton"
                    dojoType="dijit.form.Button" onSubmit="processForm">
                    Submit
                    </button>

PHP


<?php
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/plain; charset=utf-8");

//database parameters
$sDBServer = "localhost";
$sDBName = "eLearningDatabase";
$sDBUsername = "root";
$sDBPassword = "xxxx";

if(isset($_POST['submit'])) {

if(isset($_POST['firstName']))     $sfirstName = $_POST["firstName"];
if(isset($_POST['lastName']))     $slastName = $_POST["lastName"];
if(isset($_POST['email']))         $semail = $_POST["email"];
if(isset($_POST['interestField'])) $sinterestField = $_POST["interestField"];
if(isset($_POST['userName']))     $suserName = $_POST["userName"];
if(isset($_POST['password']))     $spassword= $_POST["password"];

$sStatus = "";

    //create the SQL query string
    $sQuery = "INSERT INTO users(userId, firstname, lastname, email, fieldOfInterest, username, password) ".
    " VALUES (0,'$sfirstName','$slastName', '$semail', '$sinterestField', '$suserName', '$spassword', NOW())";
       
    $connection = mysql_connect($sDBServer,$sDBUsername,$sDBPassword) or $sStatus = "Unable to open database";
    $db = mysql_select_db($sDBName) or $sStatus = "Unable to open database";

    $oResult = mysql_query($sQuery);
   
    if($oResult) {
        echo("{valid : successful, message : Hello $sfirstName! Sign up was successful. Please click the continue button below to begin using this application.
        your id number is }");
    } else {
        echo("{valid : erroneous, message : An error occured on the server. Sign up not successful. Please try again.}");
         
    }

    mysql_free_result($oResult);
    mysql_close($connection);
}

if($sStatus = ""){
    return;
}else{
    echo $sStatus;
}

?>

If anyboidy needs more to understand what i am doing, then ask and i will supply the info. Thanks to ya all


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Ajax Dojo Form Validation

by Phil Bowles :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Try dijit.form.ValidationTextBox (with required=”true”) and other dijit form widgets in your markup

 

They will automatically take care of most problems you are describing

 

Personally, I use them for their ease/power, but usually intercept the onSubmit for cross-field validation prior to xhrPost, and onValidStateChange for fancy effects on the form as the user enters data etc

 


From: dojo-interest-bounces@... [mailto:dojo-interest-bounces@...] On Behalf Of viban Terence
Sent: 2009-11-05 17:28
To: dojo-interest@...
Subject: [Dojo-interest] Ajax Dojo Form Validation

 

 

Hello everyone,

I am using a form widget to send data to my server. I have validated the single fields of the form, but still i want to do a second validation when the form is submitted just incase someone tries to submit without filling any of the fields.
This means i have to capture the onSubmit event, stop its propagation and then do my second validation. The idea here is to use dojo.every and stop at the first occurance of invalidity and the "invalidmessage" message attached to my  ValidationTextbox will be showed. If everything is fine, i want to xhrPost the message to the server and write it to the database and send a success  or an error message back which should be displayed to the user.

I have understood the theory but my implementation does not work. When i try to submit without filling anthing, nothing happens. But when i fill out the form and click submit, the page with the form simply reloads and nothing is sent to the server. What am i doing wrong? secondly where ist it best to attach the url? as a parameter to xhrPost of at the "action" artribute of the form. I need help with this stuff. I have included bits of my code. Please HELP

JAVASCRIPT/DOJO

// The function processForm will be used to process form before submitting form data to server
function processForm(){
   
    var button = dijit.byId("submitButton");

    dojo.connect(button, "onSubmit", function(evt) {
        //Stop the submit event and check field forms one after the othef
        evt.preventDefault();
        evt.stopPropagation();
       
        var mySignupForm = dijit.byId("mySignupForm");


        var invalidEntry = null;
        dojo.every(mySignupForm.getDescendants(), function(item) {
            invalidEntry = item;
            return !item.isValid || item.isValid();
        });
        if (invalidEntry != null) {
            // set focus to first field with an error
            invalidEntry.focus();
        } else {
            sendForm();
        }

});
}

function sendForm(){
    var mySignupForm = dijit.byId("mySignupForm");
    var query = dojo.formToQuery("mySignupForm");
    var xhrArgs = {
            url: "../../server/validation/saveUserData.php",
            form: dijit.byId("mySignupForm"),
            postData: query,
            handleAs: "json",
            load: function(response) {
                dojo.byId("mainpane").innerHTML = response;
            },
            error: function(error) {
                dojo.byId("mainpane").innerHTML = response;
            }
        };
        var deferred = dojo.xhrPost(xhrArgs);
}


Portions of HTML

Here i define my form widget

<form  id="mySignupForm"  name="userInfo" method ="post"
            dojoType="dijit.form.Form"/>
            <fieldset>

and here my button

<button class="formInputButton" type="submit" name="signupButton" id="signupButton"
                    dojoType="dijit.form.Button" onSubmit="processForm">
                    Submit
                    </button>

PHP


<?php
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/plain; charset=utf-8");

//database parameters
$sDBServer = "localhost";
$sDBName = "eLearningDatabase";
$sDBUsername = "root";
$sDBPassword = "xxxx";

if(isset($_POST['submit'])) {

if(isset($_POST['firstName']))     $sfirstName = $_POST["firstName"];
if(isset($_POST['lastName']))     $slastName = $_POST["lastName"];
if(isset($_POST['email']))         $semail = $_POST["email"];
if(isset($_POST['interestField'])) $sinterestField = $_POST["interestField"];
if(isset($_POST['userName']))     $suserName = $_POST["userName"];
if(isset($_POST['password']))     $spassword= $_POST["password"];

$sStatus = "";

    //create the SQL query string
    $sQuery = "INSERT INTO users(userId, firstname, lastname, email, fieldOfInterest, username, password) ".
    " VALUES (0,'$sfirstName','$slastName', '$semail', '$sinterestField', '$suserName', '$spassword', NOW())";
       
    $connection = mysql_connect($sDBServer,$sDBUsername,$sDBPassword) or $sStatus = "Unable to open database";
    $db = mysql_select_db($sDBName) or $sStatus = "Unable to open database";

    $oResult = mysql_query($sQuery);
   
    if($oResult) {
        echo("{valid : successful, message : Hello $sfirstName! Sign up was successful. Please click the continue button below to begin using this application.
        your id number is }");
    } else {
        echo("{valid : erroneous, message : An error occured on the server. Sign up not successful. Please try again.}");
         
    }

    mysql_free_result($oResult);
    mysql_close($connection);

}

if($sStatus = ""){
    return;
}else{
    echo $sStatus;
}

?>


If anyboidy needs more to understand what i am doing, then ask and i will supply the info. Thanks to ya all

 


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Ajax Dojo Form Validation

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
NO IDEAS?


From: viban Terence <vibanterence@...>
To: dojo-interest@...
Sent: Thu, November 5, 2009 6:28:12 PM
Subject: [Dojo-interest] Ajax Dojo Form Validation


Hello everyone,

I am using a form widget to send data to my server. I have validated the single fields of the form, but still i want to do a second validation when the form is submitted just incase someone tries to submit without filling any of the fields.
This means i have to capture the onSubmit event, stop its propagation and then do my second validation. The idea here is to use dojo.every and stop at the first occurance of invalidity and the "invalidmessage" message attached to my  ValidationTextbox will be showed. If everything is fine, i want to xhrPost the message to the server and write it to the database and send a success  or an error message back which should be displayed to the user.

I have understood the theory but my implementation does not work. When i try to submit without filling anthing, nothing happens. But when i fill out the form and click submit, the page with the form simply reloads and nothing is sent to the server. What am i doing wrong? secondly where ist it best to attach the url? as a parameter to xhrPost of at the "action" artribute of the form. I need help with this stuff. I have included bits of my code. Please HELP

JAVASCRIPT/DOJO

// The function processForm will be used to process form before submitting form data to server
function processForm(){
   
    var button = dijit.byId("submitButton");

    dojo.connect(button, "onSubmit", function(evt) {
        //Stop the submit event and check field forms one after the othef
        evt.preventDefault();
        evt.stopPropagation();
       
        var mySignupForm = dijit.byId("mySignupForm");

        var invalidEntry = null;
        dojo.every(mySignupForm.getDescendants(), function(item) {
            invalidEntry = item;
            return !item.isValid || item.isValid();
        });
        if (invalidEntry != null) {
            // set focus to first field with an error
            invalidEntry.focus();
        } else {
            sendForm();
        }

});
}
function sendForm(){
    var mySignupForm = dijit.byId("mySignupForm");
    var query = dojo.formToQuery("mySignupForm");
    var xhrArgs = {
            url: "../../server/validation/saveUserData.php",
            form: dijit.byId("mySignupForm"),
            postData: query,
            handleAs: "json",
            load: function(response) {
                dojo.byId("mainpane").innerHTML = response;
            },
            error: function(error) {
                dojo.byId("mainpane").innerHTML = response;
            }
        };
        var deferred = dojo.xhrPost(xhrArgs);
}

Portions of HTML

Here i define my form widget

<form  id="mySignupForm"  name="userInfo" method ="post"
            dojoType="dijit.form.Form"/>
            <fieldset>

and here my button

<button class="formInputButton" type="submit" name="signupButton" id="signupButton"
                    dojoType="dijit.form.Button" onSubmit="processForm">
                    Submit
                    </button>

PHP


<?php
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/plain; charset=utf-8");

//database parameters
$sDBServer = "localhost";
$sDBName = "eLearningDatabase";
$sDBUsername = "root";
$sDBPassword = "xxxx";

if(isset($_POST['submit'])) {

if(isset($_POST['firstName']))     $sfirstName = $_POST["firstName"];
if(isset($_POST['lastName']))     $slastName = $_POST["lastName"];
if(isset($_POST['email']))         $semail = $_POST["email"];
if(isset($_POST['interestField'])) $sinterestField = $_POST["interestField"];
if(isset($_POST['userName']))     $suserName = $_POST["userName"];
if(isset($_POST['password']))     $spassword= $_POST["password"];

$sStatus = "";

    //create the SQL query string
    $sQuery = "INSERT INTO users(userId, firstname, lastname, email, fieldOfInterest, username, password) ".
    " VALUES (0,'$sfirstName','$slastName', '$semail', '$sinterestField', '$suserName', '$spassword', NOW())";
       
    $connection = mysql_connect($sDBServer,$sDBUsername,$sDBPassword) or $sStatus = "Unable to open database";
    $db = mysql_select_db($sDBName) or $sStatus = "Unable to open database";

    $oResult = mysql_query($sQuery);
   
    if($oResult) {
        echo("{valid : successful, message : Hello $sfirstName! Sign up was successful. Please click the continue button below to begin using this application.
        your id number is }");
    } else {
        echo("{valid : erroneous, message : An error occured on the server. Sign up not successful. Please try again.}");
         
    }

    mysql_free_result($oResult);
    mysql_close($connection);
}

if($sStatus = ""){
    return;
}else{
    echo $sStatus;
}

?>

If anyboidy needs more to understand what i am doing, then ask and i will supply the info. Thanks to ya all



_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Ajax Dojo Form Validation

by Nathan Toone-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

How about:

1 - don't hijack threads...start new ones
2 - be a bit more patient...your original request was just 1 hour ago
3 - DON'T YELL
4 - Phil just sent a solution, not 10 minutes ago

-Nathan

On Nov 5, 2009, at 11:43 AM, viban Terence wrote:

NO IDEAS?


From: viban Terence <vibanterence@...>
To: dojo-interest@...
Sent: Thu, November 5, 2009 6:28:12 PM
Subject: [Dojo-interest] Ajax Dojo Form Validation


Hello everyone,

I am using a form widget to send data to my server. I have validated the single fields of the form, but still i want to do a second validation when the form is submitted just incase someone tries to submit without filling any of the fields.
This means i have to capture the onSubmit event, stop its propagation and then do my second validation. The idea here is to use dojo.every and stop at the first occurance of invalidity and the "invalidmessage" message attached to my  ValidationTextbox will be showed. If everything is fine, i want to xhrPost the message to the server and write it to the database and send a success  or an error message back which should be displayed to the user.

I have understood the theory but my implementation does not work. When i try to submit without filling anthing, nothing happens. But when i fill out the form and click submit, the page with the form simply reloads and nothing is sent to the server. What am i doing wrong? secondly where ist it best to attach the url? as a parameter to xhrPost of at the "action" artribute of the form. I need help with this stuff. I have included bits of my code. Please HELP

JAVASCRIPT/DOJO

// The function processForm will be used to process form before submitting form data to server
function processForm(){
    
    var button = dijit.byId("submitButton");

    dojo.connect(button, "onSubmit", function(evt) {
        //Stop the submit event and check field forms one after the othef
        evt.preventDefault();
        evt.stopPropagation();
        
        var mySignupForm = dijit.byId("mySignupForm");

        var invalidEntry = null;
        dojo.every(mySignupForm.getDescendants(), function(item) {
            invalidEntry = item;
            return !item.isValid || item.isValid();
        });
        if (invalidEntry != null) {
            // set focus to first field with an error
            invalidEntry.focus();
        } else {
            sendForm();
        }

});
}
function sendForm(){
    var mySignupForm = dijit.byId("mySignupForm");
    var query = dojo.formToQuery("mySignupForm");
    var xhrArgs = {
            url: "../../server/validation/saveUserData.php",
            form: dijit.byId("mySignupForm"),
            postData: query,
            handleAs: "json",
            load: function(response) {
                dojo.byId("mainpane").innerHTML = response;
            },
            error: function(error) {
                dojo.byId("mainpane").innerHTML = response;
            }
        };
        var deferred = dojo.xhrPost(xhrArgs);
}

Portions of HTML

Here i define my form widget

<form  id="mySignupForm"  name="userInfo" method ="post"
            dojoType="dijit.form.Form"/>
            <fieldset>

and here my button

<button class="formInputButton" type="submit" name="signupButton" id="signupButton"
                    dojoType="dijit.form.Button" onSubmit="processForm">
                    Submit
                    </button>

PHP


<?php
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/plain; charset=utf-8");

//database parameters
$sDBServer = "localhost";
$sDBName = "eLearningDatabase";
$sDBUsername = "root";
$sDBPassword = "xxxx";

if(isset($_POST['submit'])) {

if(isset($_POST['firstName']))     $sfirstName = $_POST["firstName"];
if(isset($_POST['lastName']))     $slastName = $_POST["lastName"];
if(isset($_POST['email']))         $semail = $_POST["email"];
if(isset($_POST['interestField'])) $sinterestField = $_POST["interestField"];
if(isset($_POST['userName']))     $suserName = $_POST["userName"];
if(isset($_POST['password']))     $spassword= $_POST["password"];

$sStatus = "";

    //create the SQL query string
    $sQuery = "INSERT INTO users(userId, firstname, lastname, email, fieldOfInterest, username, password) ".
    " VALUES (0,'$sfirstName','$slastName', '$semail', '$sinterestField', '$suserName', '$spassword', NOW())";
        
    $connection = mysql_connect($sDBServer,$sDBUsername,$sDBPassword) or $sStatus = "Unable to open database";
    $db = mysql_select_db($sDBName) or $sStatus = "Unable to open database";

    $oResult = mysql_query($sQuery);
    
    if($oResult) {
        echo("{valid : successful, message : Hello $sfirstName! Sign up was successful. Please click the continue button below to begin using this application.
        your id number is }");
    } else {
        echo("{valid : erroneous, message : An error occured on the server. Sign up not successful. Please try again.}");
         
    }

    mysql_free_result($oResult);
    mysql_close($connection);
}

if($sStatus = ""){
    return;
}else{
    echo $sStatus;
}

?>

If anyboidy needs more to understand what i am doing, then ask and i will supply the info. Thanks to ya all


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

smime.p7s (3K) Download Attachment

Re: Ajax Dojo Form Validation

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I apologise, my mistake

I have tried using  validate() which returns if the form is valid - same as isValid - but provides a few additional (ui-specific) features. 1 - it will highlight any sub-widgets that are not valid 2 - it will call focus() on the first invalid sub-widget. This is exactly what i wanted. But still it fails.

Thanks

From: Nathan Toone <toonetown@...>
To: dojo-interest@...
Sent: Thu, November 5, 2009 7:51:40 PM
Subject: Re: [Dojo-interest] Ajax Dojo Form Validation

How about:

1 - don't hijack threads...start new ones
2 - be a bit more patient...your original request was just 1 hour ago
3 - DON'T YELL
4 - Phil just sent a solution, not 10 minutes ago

-Nathan

On Nov 5, 2009, at 11:43 AM, viban Terence wrote:

NO IDEAS?


From: viban Terence <vibanterence@...>
To: dojo-interest@...
Sent: Thu, November 5, 2009 6:28:12 PM
Subject: [Dojo-interest] Ajax Dojo Form Validation


Hello everyone,

I am using a form widget to send data to my server. I have validated the single fields of the form, but still i want to do a second validation when the form is submitted just incase someone tries to submit without filling any of the fields.
This means i have to capture the onSubmit event, stop its propagation and then do my second validation. The idea here is to use dojo.every and stop at the first occurance of invalidity and the "invalidmessage" message attached to my  ValidationTextbox will be showed. If everything is fine, i want to xhrPost the message to the server and write it to the database and send a success  or an error message back which should be displayed to the user.

I have understood the theory but my implementation does not work. When i try to submit without filling anthing, nothing happens. But when i fill out the form and click submit, the page with the form simply reloads and nothing is sent to the server. What am i doing wrong? secondly where ist it best to attach the url? as a parameter to xhrPost of at the "action" artribute of the form. I need help with this stuff. I have included bits of my code. Please HELP

JAVASCRIPT/DOJO

// The function processForm will be used to process form before submitting form data to server
function processForm(){
    
    var button = dijit.byId("submitButton");

    dojo.connect(button, "onSubmit", function(evt) {
        //Stop the submit event and check field forms one after the othef
        evt.preventDefault();
        evt.stopPropagation();
        
        var mySignupForm = dijit.byId("mySignupForm");

        var invalidEntry = null;
        dojo.every(mySignupForm.getDescendants(), function(item) {
            invalidEntry = item;
            return !item.isValid || item.isValid();
        });
        if (invalidEntry != null) {
            // set focus to first field with an error
            invalidEntry.focus();
        } else {
            sendForm();
        }

});
}
function sendForm(){
    var mySignupForm = dijit.byId("mySignupForm");
    var query = dojo.formToQuery("mySignupForm");
    var xhrArgs = {
            url: "../../server/validation/saveUserData.php",
            form: dijit.byId("mySignupForm"),
            postData: query,
            handleAs: "json",
            load: function(response) {
                dojo.byId("mainpane").innerHTML = response;
            },
            error: function(error) {
                dojo.byId("mainpane").innerHTML = response;
            }
        };
        var deferred = dojo.xhrPost(xhrArgs);
}

Portions of HTML

Here i define my form widget

<form  id="mySignupForm"  name="userInfo" method ="post"
            dojoType="dijit.form.Form"/>
            <fieldset>

and here my button

<button class="formInputButton" type="submit" name="signupButton" id="signupButton"
                    dojoType="dijit.form.Button" onSubmit="processForm">
                    Submit
                    </button>

PHP


<?php
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: text/plain; charset=utf-8");

//database parameters
$sDBServer = "localhost";
$sDBName = "eLearningDatabase";
$sDBUsername = "root";
$sDBPassword = "xxxx";

if(isset($_POST['submit'])) {

if(isset($_POST['firstName']))     $sfirstName = $_POST["firstName"];
if(isset($_POST['lastName']))     $slastName = $_POST["lastName"];
if(isset($_POST['email']))         $semail = $_POST["email"];
if(isset($_POST['interestField'])) $sinterestField = $_POST["interestField"];
if(isset($_POST['userName']))     $suserName = $_POST["userName"];
if(isset($_POST['password']))     $spassword= $_POST["password"];

$sStatus = "";

    //create the SQL query string
    $sQuery = "INSERT INTO users(userId, firstname, lastname, email, fieldOfInterest, username, password) ".
    " VALUES (0,'$sfirstName','$slastName', '$semail', '$sinterestField', '$suserName', '$spassword', NOW())";
        
    $connection = mysql_connect($sDBServer,$sDBUsername,$sDBPassword) or $sStatus = "Unable to open database";
    $db = mysql_select_db($sDBName) or $sStatus = "Unable to open database";

    $oResult = mysql_query($sQuery);
    
    if($oResult) {
        echo("{valid : successful, message : Hello $sfirstName! Sign up was successful. Please click the continue button below to begin using this application.
        your id number is }");
    } else {
        echo("{valid : erroneous, message : An error occured on the server. Sign up not successful. Please try again.}");
         
    }

    mysql_free_result($oResult);
    mysql_close($connection);
}

if($sStatus = ""){
    return;
}else{
    echo $sStatus;
}

?>

If anyboidy needs more to understand what i am doing, then ask and i will supply the info. Thanks to ya all


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Ajax Dojo Form Validation

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello everyone,
i am having trouble stopping the default submitting to form data to my server. here is how i define my form widget

<form method="" action="" id="mySignupForm" name="mySignupForm" dojoType="dijit.form.Form"
            onSubmit="javascript: return checkFormValidation();" onReset="javascript: resetFormData();" >

in this case the onSubmit should mimic the depreciate "execute" attribute. So my question....How can i prevent the form from submitting using preventDefault or dojo.stop?????
secondly i am using xhrPost and as far as i know, i can either pass the server url as the form "action" attribute or in the url attribute of xhrPost. Which one works better?. Thanks in advance.




_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Form Widget

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hi
- How can i stop the form from being submitted when user clicks? would like to do validation. dojo.Event(e) seems to be working (see code snippet below) for IE but not Firefox. Say this because the url does not change for Firefox.
- Secondly i am sending the data via xhrPost and for IE I can successfully write the data to the database, but firefox doesn't seem to work.
-Finally how can i prevent the form reloading each time i click submit. Even when IE write to the database , the action defined in the xhrPost load function does not occur.

I am new to this stuff and although i find dojo awesome, i am really frustrated with small issues like this. This problems have costed me two days already, so i would appreciate all the help i can get. Thx

<form id="mySignupForm" method="" action="" name="mySignupForm" dojoType="dijit.form.Form"
            onSubmit="javascript: return checkFormValidation(); return dojo.stopEvent(e);" onReset="javascript: resetFormData();" >


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Form Widget

by Miguel Coquet :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I see a couple of suspicious things , I can't test right now, but out of the top of my head they are:

1) The return checkFormValidation() first, will prevent the dojo.stopEvent(e). It should look like onSubmit="dojo.stopEvent(e); return checkFormValidation();"
2) the e object might not exist. What I usually do is:


<form id="mySignupForm" method="" action="" name="mySignupForm" dojoType="dijit.form.Form" onReset="resetFormData">
<script type="dojo/method" event="onSubmit" args="e">

// e now, is the first argument the onSubmit method gets when its executed. Events usually get varying arguments, but we only care right now about the event object, wich we called e using args="e"
e.preventDefault(); //this should do the same as dojo.stopEvent(e);
//this script is running with the form widget as scope, so "this" points at the form widget object. 
if ( this.isValid() )  //tests if all the widgets in the form are valid. See the Validation form widgets docs for details on this
{
dojo.xhrPost({
form:this.domNode,
url:'my/serverside/script.php',
load: function(){ alert('yay loaded') },
error: function(){ alert('The server didnt like the request.') }
});
}
else
{
this.validate(); //this will force the validation of the form widgets to execute and visually show the user feedback. See docs for details
}
</script>

If you are using dijit.form.* widgets in your form and setting proper validation rules in them, this will work very well for you. If not, feel free to not use the this.isValid for validation , and just execute your own method of validation inside that script.

Hope that helps, and good luck :)


Miguel




On 2009/11/07, at 11:00, viban Terence wrote:

Hi
- How can i stop the form from being submitted when user clicks? would like to do validation. dojo.Event(e) seems to be working (see code snippet below) for IE but not Firefox. Say this because the url does not change for Firefox. 
- Secondly i am sending the data via xhrPost and for IE I can successfully write the data to the database, but firefox doesn't seem to work.
-Finally how can i prevent the form reloading each time i click submit. Even when IE write to the database , the action defined in the xhrPost load function does not occur.

I am new to this stuff and although i find dojo awesome, i am really frustrated with small issues like this. This problems have costed me two days already, so i would appreciate all the help i can get. Thx

<form id="mySignupForm" method="" action="" name="mySignupForm" dojoType="dijit.form.Form" 
            onSubmit="javascript: return checkFormValidation(); return dojo.stopEvent(e);" onReset="javascript: resetFormData();" >

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Form Widget

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello Miguel,

thanks a lot for taking the time to help. I followed you suggestion and everything is working fine. I am now able to write my data asynchronously to the database. Here again is how i did it in case anyone else wants to use this or looks it up in the future

<form id="mySignupForm" method="" action="" name="mySignupForm" dojoType="dijit.form.Form"  onReset="resetFormData();">
            <script type="dojo/method" event="onSubmit" args="e">
                checkFormValidation(e);
            </script>

function checkFormValidation(evt) {
    dojo.stopEvent(evt);
    var firstname = dijit.byId("firstName").attr("value");
    if (!dijit.byId("mySignupForm").validate() && (firstname == "") ) {
        alert("Form contains invalid data.  Please correct first");
        return false;
    }else{
        var message = confirm("Form is valid, press OK to submit");
        //return message;
        if(message == true){
            sendform();
        }else{
            return false;
        }
    }     
}

function sendform(){
    var query = dojo.formToQuery("mySignupForm");
    var url = "../../server/validation/saveUserData.php";
    var xhrArgs = {
            url: url,
            handleAS: "json",
            postData: query,
            //timeout: 300,
            form: "mySignupForm",
            handle: handleSendData
    };
    var deferred = dojo.xhrPost(xhrArgs);
    return deferred;
}

handleSenddata can then be written to do what you like. My server-side code writes the form elements to the database and returns either {valid:true} for success and {valid : false}. I then use this to let the user know there was a problem or grant him access to my application. Also return response in "handleSendData" so that it can be used by the "deferred " object to do include more callback functions or error handling functions. That is also why i am returning deferred. Have not added my form because it will be too big, but if anyone ever needs it of the php code ..let me know

Thanks again Miguel

auf Wiedersehen

From: Miguel Coquet <mcoquet@...>
To: dojo-interest@...
Sent: Sat, November 7, 2009 12:58:58 PM
Subject: Re: [Dojo-interest] Form Widget

I see a couple of suspicious things , I can't test right now, but out of the top of my head they are:

1) The return checkFormValidation() first, will prevent the dojo.stopEvent(e). It should look like onSubmit="dojo.stopEvent(e); return checkFormValidation();"
2) the e object might not exist. What I usually do is:


<form id="mySignupForm" method="" action="" name="mySignupForm" dojoType="dijit.form.Form" onReset="resetFormData">
<script type="dojo/method" event="onSubmit" args="e">

// e now, is the first argument the onSubmit method gets when its executed. Events usually get varying arguments, but we only care right now about the event object, wich we called e using args="e"
e.preventDefault(); //this should do the same as dojo.stopEvent(e);
//this script is running with the form widget as scope, so "this" points at the form widget object. 
if ( this.isValid() )  //tests if all the widgets in the form are valid. See the Validation form widgets docs for details on this
{
dojo.xhrPost({
form:this.domNode,
url:'my/serverside/script.php',
load: function(){ alert('yay loaded') },
error: function(){ alert('The server didnt like the request.') }
});
}
else
{
this.validate(); //this will force the validation of the form widgets to execute and visually show the user feedback. See docs for details
}
</script>

If you are using dijit.form.* widgets in your form and setting proper validation rules in them, this will work very well for you. If not, feel free to not use the this.isValid for validation , and just execute your own method of validation inside that script.

Hope that helps, and good luck :)


Miguel




On 2009/11/07, at 11:00, viban Terence wrote:

Hi
- How can i stop the form from being submitted when user clicks? would like to do validation. dojo.Event(e) seems to be working (see code snippet below) for IE but not Firefox. Say this because the url does not change for Firefox. 
- Secondly i am sending the data via xhrPost and for IE I can successfully write the data to the database, but firefox doesn't seem to work.
-Finally how can i prevent the form reloading each time i click submit. Even when IE write to the database , the action defined in the xhrPost load function does not occur.

I am new to this stuff and although i find dojo awesome, i am really frustrated with small issues like this. This problems have costed me two days already, so i would appreciate all the help i can get. Thx

<form id="mySignupForm" method="" action="" name="mySignupForm" dojoType="dijit.form.Form" 
            onSubmit="javascript: return checkFormValidation(); return dojo.stopEvent(e);" onReset="javascript: resetFormData();" >

_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest



_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Parsing JSON with DOJO

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hello everyone,

Been having problems parsing my dojo learning object. I have pasted a section of what i get from the "responseText" from the server. y the way, i am getting this elearning objects from another server in xml format, and then using a resource i found here () to get the json format. Each object has categories which begin with a root (in this case it is just "lo"), then other categories are "general", "educational" etc. all this define according to the ieee lom standard. But that is all beside the point. The "general" category has "title", "description" and i need to extract the information here. Also the "content" category has "paragraph" nodes whose information i also need.
QUESTION, how do i parse a json file like this one to get the information i need. Do i need to create a data store? if yes how? do i need to do more work on the server? I will appreciate all the answers i can get. This issue has slowed me down considerable.

Here a section of the data. The categories are marked in blue.


[{"lo":{"@attributes":{"path":"\/HyLOs\/content\/Data\/MIPv6\/MobilInter\/MobilInter","lastmod":"2007-11-13T22:17+0100"},"general":{"title":"Mobile Internet","language":"en","description":"This course introduces protocols and management schemes for mobility in the next generation Internet. It presents current mobility extensions of IPv6 as designed to create a realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the basic","keywords":["Internet Protocol","MIPv4","MIPv6","Mobile Internet","Standard"],"coverage":"Mobility Management in the Next Generation Internet","structure":"Hierarchical","aggregationLevel":"1"},"educational":{"interactivityType":"Expositive","learningResourceType":"unit","interactivityLevel":"low","semanticDensity":"high","intendedEndUserRole":"Learner","context":"UniversitySecondCycle","typicalAgeRange":"20_30","difficulty":"medium","typicalLearningTime":"60","description":"Beim Erstellen des Lernobjektes autmatisch erzeugter Eintrag.","language":""},"rights":"","lifecycle":{"status":"Draft","version":"1","contribute":[{"datetime":"2007-11-13T20:30+0100","role":"Author"},{"datetime":"2007-11-13T20:37+0100","role":"Author"},{"datetime":"2007-11-13T20:40+0100","role":"Author"},{"datetime":"2007-11-13T20:57+0100","role":"Author"},{"datetime":"2007-11-13T22:09+0100","role":"Author"},{"datetime":"2007-11-13T22:14+0100","role":"Author"}]},"content":{"section":"Mobility Management in the Next Generation Internet","paragraph":"This course introduces protocols and management schemes for mobility in the next generation Internet. It presents current mobility extensions of IPv6 as designed to create a realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the basic end-to-endmobility managment protocol, we discuss performace and security issues, as well as recentimprovements to enhance mobility operations within the next generation Internet protocol."},"bibList":""}}, (This is where the next learning object begins) {"lo":{"@


THANK YOU


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Parsing JSON with DOJO

by jaredj :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

1.)  If you're using dojo.xhrGet, why not just use handleAs: "json"  ?
http://docs.dojocampus.org/dojo/xhrGet

As it returns a JavaScript object (In this case it would be an array).

To access data in it, you can just iterate the array as you would any
javaScriot object and access attributes of it.   Eg:

var i;
for (i = 0; i < data.length; i++){
    var entry = data[i];
    console.log(entry.title);
    console.log(entry.description);
    // and so on.
}

-- Jared


On Thu, Nov 12, 2009 at 7:03 AM, viban Terence <vibanterence@...> wrote:

> Hello everyone,
>
> Been having problems parsing my dojo learning object. I have pasted a
> section of what i get from the "responseText" from the server. y the way, i
> am getting this elearning objects from another server in xml format, and
> then using a resource i found here () to get the json format. Each object
> has categories which begin with a root (in this case it is just "lo"), then
> other categories are "general", "educational" etc. all this define according
> to the ieee lom standard. But that is all beside the point. The "general"
> category has "title", "description" and i need to extract the information
> here. Also the "content" category has "paragraph" nodes whose information i
> also need.
> QUESTION, how do i parse a json file like this one to get the information i
> need. Do i need to create a data store? if yes how? do i need to do more
> work on the server? I will appreciate all the answers i can get. This issue
> has slowed me down considerable.
>
> Here a section of the data. The categories are marked in blue.
>
>
> [{"lo":{"@attributes":{"path":"\/HyLOs\/content\/Data\/MIPv6\/MobilInter\/MobilInter","lastmod":"2007-11-13T22:17+0100"},"general":{"title":"Mobile
> Internet","language":"en","description":"This course introduces protocols
> and management schemes for mobility in the next generation Internet. It
> presents current mobility extensions of IPv6 as designed to create a
> realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the
> basic","keywords":["Internet Protocol","MIPv4","MIPv6","Mobile
> Internet","Standard"],"coverage":"Mobility Management in the Next Generation
> Internet","structure":"Hierarchical","aggregationLevel":"1"},"educational":{"interactivityType":"Expositive","learningResourceType":"unit","interactivityLevel":"low","semanticDensity":"high","intendedEndUserRole":"Learner","context":"UniversitySecondCycle","typicalAgeRange":"20_30","difficulty":"medium","typicalLearningTime":"60","description":"Beim
> Erstellen des Lernobjektes autmatisch erzeugter
> Eintrag.","language":""},"rights":"","lifecycle":{"status":"Draft","version":"1","contribute":[{"datetime":"2007-11-13T20:30+0100","role":"Author"},{"datetime":"2007-11-13T20:37+0100","role":"Author"},{"datetime":"2007-11-13T20:40+0100","role":"Author"},{"datetime":"2007-11-13T20:57+0100","role":"Author"},{"datetime":"2007-11-13T22:09+0100","role":"Author"},{"datetime":"2007-11-13T22:14+0100","role":"Author"}]},"content":{"section":"Mobility
> Management in the Next Generation Internet","paragraph":"This course
> introduces protocols and management schemes for mobility in the next
> generation Internet. It presents current mobility extensions of IPv6 as
> designed to create a realtimecompliant, secure mobile Internet. Starting
> from Mobile IPv6, the basic end-to-endmobility managment protocol, we
> discuss performace and security issues, as well as recentimprovements to
> enhance mobility operations within the next generation Internet
> protocol."},"bibList":""}}, (This is where the next learning object begins)
> {"lo":{"@
>
>
> THANK YOU
>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Parsing JSON with DOJO

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Hallo Jared,

thanks for your swift reply. I am doing a dojo.xhrGet and  using handleAs: "json". When i try to iterate the array as you suggest, all i get  is "undefined" and i do not unserstand what this means.
Can this have something to do with the format of the json file here?.....i am really lost. I have checked the json in a json validator, and it seems to be fine. So i really have no idea what is going on. I thought switching from xml to json, would make things easy especially as i will be using dojo alot.

Please just check to see if i am missing something, cause i know i am. Thanks again



From: Jared Jurkiewicz <jared.jurkiewicz@...>
To: dojo-interest@...
Sent: Thu, November 12, 2009 3:30:01 PM
Subject: Re: [Dojo-interest] Parsing JSON with DOJO

1.)  If you're using dojo.xhrGet, why not just use handleAs: "json"  ?
http://docs.dojocampus.org/dojo/xhrGet

As it returns a JavaScript object (In this case it would be an array).

To access data in it, you can just iterate the array as you would any
javaScriot object and access attributes of it.  Eg:

var i;
for (i = 0; i < data.length; i++){
    var entry = data[i];
    console.log(entry.title);
    console.log(entry.description);
    // and so on.
}

-- Jared


On Thu, Nov 12, 2009 at 7:03 AM, viban Terence <vibanterence@...> wrote:

> Hello everyone,
>
> Been having problems parsing my dojo learning object. I have pasted a
> section of what i get from the "responseText" from the server. y the way, i
> am getting this elearning objects from another server in xml format, and
> then using a resource i found here () to get the json format. Each object
> has categories which begin with a root (in this case it is just "lo"), then
> other categories are "general", "educational" etc. all this define according
> to the ieee lom standard. But that is all beside the point. The "general"
> category has "title", "description" and i need to extract the information
> here. Also the "content" category has "paragraph" nodes whose information i
> also need.
> QUESTION, how do i parse a json file like this one to get the information i
> need. Do i need to create a data store? if yes how? do i need to do more
> work on the server? I will appreciate all the answers i can get. This issue
> has slowed me down considerable.
>
> Here a section of the data. The categories are marked in blue.
>
>
> [{"lo":{"@attributes":{"path":"\/HyLOs\/content\/Data\/MIPv6\/MobilInter\/MobilInter","lastmod":"2007-11-13T22:17+0100"},"general":{"title":"Mobile
> Internet","language":"en","description":"This course introduces protocols
> and management schemes for mobility in the next generation Internet. It
> presents current mobility extensions of IPv6 as designed to create a
> realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the
> basic","keywords":["Internet Protocol","MIPv4","MIPv6","Mobile
> Internet","Standard"],"coverage":"Mobility Management in the Next Generation
> Internet","structure":"Hierarchical","aggregationLevel":"1"},"educational":{"interactivityType":"Expositive","learningResourceType":"unit","interactivityLevel":"low","semanticDensity":"high","intendedEndUserRole":"Learner","context":"UniversitySecondCycle","typicalAgeRange":"20_30","difficulty":"medium","typicalLearningTime":"60","description":"Beim
> Erstellen des Lernobjektes autmatisch erzeugter
> Eintrag.","language":""},"rights":"","lifecycle":{"status":"Draft","version":"1","contribute":[{"datetime":"2007-11-13T20:30+0100","role":"Author"},{"datetime":"2007-11-13T20:37+0100","role":"Author"},{"datetime":"2007-11-13T20:40+0100","role":"Author"},{"datetime":"2007-11-13T20:57+0100","role":"Author"},{"datetime":"2007-11-13T22:09+0100","role":"Author"},{"datetime":"2007-11-13T22:14+0100","role":"Author"}]},"content":{"section":"Mobility
> Management in the Next Generation Internet","paragraph":"This course
> introduces protocols and management schemes for mobility in the next
> generation Internet. It presents current mobility extensions of IPv6 as
> designed to create a realtimecompliant, secure mobile Internet. Starting
> from Mobile IPv6, the basic end-to-endmobility managment protocol, we
> discuss performace and security issues, as well as recentimprovements to
> enhance mobility operations within the next generation Internet
> protocol."},"bibList":""}}, (This is where the next learning object begins)
> {"lo":{"@
>
>
> THANK YOU
>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Parsing JSON with DOJO

by jaredj :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Post the code on how you are iterating.


On Thu, Nov 12, 2009 at 11:14 AM, viban Terence <vibanterence@...> wrote:

> Hallo Jared,
>
> thanks for your swift reply. I am doing a dojo.xhrGet and  using handleAs:
> "json". When i try to iterate the array as you suggest, all i get  is
> "undefined" and i do not unserstand what this means.
> Can this have something to do with the format of the json file here?.....i
> am really lost. I have checked the json in a json validator, and it seems to
> be fine. So i really have no idea what is going on. I thought switching from
> xml to json, would make things easy especially as i will be using dojo alot.
>
> Please just check to see if i am missing something, cause i know i am.
> Thanks again
>
>
> ________________________________
> From: Jared Jurkiewicz <jared.jurkiewicz@...>
> To: dojo-interest@...
> Sent: Thu, November 12, 2009 3:30:01 PM
> Subject: Re: [Dojo-interest] Parsing JSON with DOJO
>
> 1.)  If you're using dojo.xhrGet, why not just use handleAs: "json"  ?
> http://docs.dojocampus.org/dojo/xhrGet
>
> As it returns a JavaScript object (In this case it would be an array).
>
> To access data in it, you can just iterate the array as you would any
> javaScriot object and access attributes of it.  Eg:
>
> var i;
> for (i = 0; i < data.length; i++){
>     var entry = data[i];
>     console.log(entry.title);
>     console.log(entry.description);
>     // and so on.
> }
>
> -- Jared
>
>
> On Thu, Nov 12, 2009 at 7:03 AM, viban Terence <vibanterence@...>
> wrote:
>> Hello everyone,
>>
>> Been having problems parsing my dojo learning object. I have pasted a
>> section of what i get from the "responseText" from the server. y the way,
>> i
>> am getting this elearning objects from another server in xml format, and
>> then using a resource i found here () to get the json format. Each object
>> has categories which begin with a root (in this case it is just "lo"),
>> then
>> other categories are "general", "educational" etc. all this define
>> according
>> to the ieee lom standard. But that is all beside the point. The "general"
>> category has "title", "description" and i need to extract the information
>> here. Also the "content" category has "paragraph" nodes whose information
>> i
>> also need.
>> QUESTION, how do i parse a json file like this one to get the information
>> i
>> need. Do i need to create a data store? if yes how? do i need to do more
>> work on the server? I will appreciate all the answers i can get. This
>> issue
>> has slowed me down considerable.
>>
>> Here a section of the data. The categories are marked in blue.
>>
>>
>>
>> [{"lo":{"@attributes":{"path":"\/HyLOs\/content\/Data\/MIPv6\/MobilInter\/MobilInter","lastmod":"2007-11-13T22:17+0100"},"general":{"title":"Mobile
>> Internet","language":"en","description":"This course introduces protocols
>> and management schemes for mobility in the next generation Internet. It
>> presents current mobility extensions of IPv6 as designed to create a
>> realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the
>> basic","keywords":["Internet Protocol","MIPv4","MIPv6","Mobile
>> Internet","Standard"],"coverage":"Mobility Management in the Next
>> Generation
>>
>> Internet","structure":"Hierarchical","aggregationLevel":"1"},"educational":{"interactivityType":"Expositive","learningResourceType":"unit","interactivityLevel":"low","semanticDensity":"high","intendedEndUserRole":"Learner","context":"UniversitySecondCycle","typicalAgeRange":"20_30","difficulty":"medium","typicalLearningTime":"60","description":"Beim
>> Erstellen des Lernobjektes autmatisch erzeugter
>>
>> Eintrag.","language":""},"rights":"","lifecycle":{"status":"Draft","version":"1","contribute":[{"datetime":"2007-11-13T20:30+0100","role":"Author"},{"datetime":"2007-11-13T20:37+0100","role":"Author"},{"datetime":"2007-11-13T20:40+0100","role":"Author"},{"datetime":"2007-11-13T20:57+0100","role":"Author"},{"datetime":"2007-11-13T22:09+0100","role":"Author"},{"datetime":"2007-11-13T22:14+0100","role":"Author"}]},"content":{"section":"Mobility
>> Management in the Next Generation Internet","paragraph":"This course
>> introduces protocols and management schemes for mobility in the next
>> generation Internet. It presents current mobility extensions of IPv6 as
>> designed to create a realtimecompliant, secure mobile Internet. Starting
>> from Mobile IPv6, the basic end-to-endmobility managment protocol, we
>> discuss performace and security issues, as well as recentimprovements to
>> enhance mobility operations within the next generation Internet
>> protocol."},"bibList":""}}, (This is where the next learning object
>> begins)
>> {"lo":{"@
>>
>>
>> THANK YOU
>>
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>>
>>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://docs.dojocampus.org
> Dojo-interest@...
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Re: Parsing JSON with DOJO

by vibanty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
here is the Javascript. I tried to print out the length of my array and instead of getting 7 as i would expect, i am getting 9907. This means each character in the file is considered as an array. This doesn't make sense, because the learning objects are comma separated. Well here is the script that makes the request and processes the response. Thanks


function eObjectHandler(response, ioArgs) {

    var error = response instanceof Error;
    var responseText = error ? response.message : ioArgs.xhr.responseText;
 
     for (i = 0; i < responseText.length; i++){
            var entry = responseText[i];
            resultNode.innerHTML = entry.tile;
            resultNode.innerHTML = entry.description;
        }
}

function hylostest() {
    dojo.xhrGet( {
        url : "../../server/requestFile.php",
        handleAs : "json",
        preventCache: "true",
        handle : eObjectHandler
    });
}


From: Jared Jurkiewicz <jared.jurkiewicz@...>
To: dojo-interest@...
Sent: Thu, November 12, 2009 5:18:31 PM
Subject: Re: [Dojo-interest] Parsing JSON with DOJO

Post the code on how you are iterating.


On Thu, Nov 12, 2009 at 11:14 AM, viban Terence <vibanterence@...> wrote:

> Hallo Jared,
>
> thanks for your swift reply. I am doing a dojo.xhrGet and  using handleAs:
> "json". When i try to iterate the array as you suggest, all i get  is
> "undefined" and i do not unserstand what this means.
> Can this have something to do with the format of the json file here?.....i
> am really lost. I have checked the json in a json validator, and it seems to
> be fine. So i really have no idea what is going on. I thought switching from
> xml to json, would make things easy especially as i will be using dojo alot.
>
> Please just check to see if i am missing something, cause i know i am.
> Thanks again
>
>
> ________________________________
> From: Jared Jurkiewicz <jared.jurkiewicz@...>
> To: dojo-interest@...
> Sent: Thu, November 12, 2009 3:30:01 PM
> Subject: Re: [Dojo-interest] Parsing JSON with DOJO
>
> 1.)  If you're using dojo.xhrGet, why not just use handleAs: "json"  ?
> http://docs.dojocampus.org/dojo/xhrGet

>
> As it returns a JavaScript object (In this case it would be an array).
>
> To access data in it, you can just iterate the array as you would any
> javaScriot object and access attributes of it.  Eg:
>
> var i;
> for (i = 0; i < data.length; i++){
>     var entry = data[i];
>     console.log(entry.title);
>     console.log(entry.description);
>     // and so on.
> }
>
> -- Jared
>
>
> On Thu, Nov 12, 2009 at 7:03 AM, viban Terence <vibanterence@...>
> wrote:
>> Hello everyone,
>>
>> Been having problems parsing my dojo learning object. I have pasted a
>> section of what i get from the "responseText" from the server. y the way,
>> i
>> am getting this elearning objects from another server in xml format, and
>> then using a resource i found here () to get the json format. Each object
>> has categories which begin with a root (in this case it is just "lo"),
>> then
>> other categories are "general", "educational" etc. all this define
>> according
>> to the ieee lom standard. But that is all beside the point. The "general"
>> category has "title", "description" and i need to extract the information
>> here. Also the "content" category has "paragraph" nodes whose information
>> i
>> also need.
>> QUESTION, how do i parse a json file like this one to get the information
>> i
>> need. Do i need to create a data store? if yes how? do i need to do more
>> work on the server? I will appreciate all the answers i can get. This
>> issue
>> has slowed me down considerable.
>>
>> Here a section of the data. The categories are marked in blue.
>>
>>
>>
>> [{"lo":{"@attributes":{"path":"\/HyLOs\/content\/Data\/MIPv6\/MobilInter\/MobilInter","lastmod":"2007-11-13T22:17+0100"},"general":{"title":"Mobile
>> Internet","language":"en","description":"This course introduces protocols
>> and management schemes for mobility in the next generation Internet. It
>> presents current mobility extensions of IPv6 as designed to create a
>> realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the
>> basic","keywords":["Internet Protocol","MIPv4","MIPv6","Mobile
>> Internet","Standard"],"coverage":"Mobility Management in the Next
>> Generation
>>
>> Internet","structure":"Hierarchical","aggregationLevel":"1"},"educational":{"interactivityType":"Expositive","learningResourceType":"unit","interactivityLevel":"low","semanticDensity":"high","intendedEndUserRole":"Learner","context":"UniversitySecondCycle","typicalAgeRange":"20_30","difficulty":"medium","typicalLearningTime":"60","description":"Beim
>> Erstellen des Lernobjektes autmatisch erzeugter
>>
>> Eintrag.","language":""},"rights":"","lifecycle":{"status":"Draft","version":"1","contribute":[{"datetime":"2007-11-13T20:30+0100","role":"Author"},{"datetime":"2007-11-13T20:37+0100","role":"Author"},{"datetime":"2007-11-13T20:40+0100","role":"Author"},{"datetime":"2007-11-13T20:57+0100","role":"Author"},{"datetime":"2007-11-13T22:09+0100","role":"Author"},{"datetime":"2007-11-13T22:14+0100","role":"Author"}]},"content":{"section":"Mobility
>> Management in the Next Generation Internet","paragraph":"This course
>> introduces protocols and management schemes for mobility in the next
>> generation Internet. It presents current mobility extensions of IPv6 as
>> designed to create a realtimecompliant, secure mobile Internet. Starting
>> from Mobile IPv6, the basic end-to-endmobility managment protocol, we
>> discuss performace and security issues, as well as recentimprovements to
>> enhance mobility operations within the next generation Internet
>> protocol."},"bibList":""}}, (This is where the next learning object
>> begins)
>> {"lo":{"@
>>
>>
>> THANK YOU
>>
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Parent Message unknown Re: Parsing JSON with DOJO

by Hockey, Ben :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
for the case where your request is succesful, swince you're using handleAs :'json', the result param passed to eObjectHandler will be the array - you don't need to get the responseText.  the responseText will be the 'raw' response which is why the length is equal to the number of chars.
 
you want to use response in your for loop instead of responseText.
 
ben...


From: dojo-interest-bounces@... [mailto:dojo-interest-bounces@...] On Behalf Of viban Terence
Sent: Thursday, November 12, 2009 11:30 AM
To: dojo-interest@...
Subject: Re: [Dojo-interest] Parsing JSON with DOJO

here is the Javascript. I tried to print out the length of my array and instead of getting 7 as i would expect, i am getting 9907. This means each character in the file is considered as an array. This doesn't make sense, because the learning objects are comma separated. Well here is the script that makes the request and processes the response. Thanks


function eObjectHandler(response, ioArgs) {

    var error = response instanceof Error;
    var responseText = error ? response.message : ioArgs.xhr.responseText;
 
     for (i = 0; i < responseText.length; i++){
            var entry = responseText[i];
            resultNode.innerHTML = entry.tile;
            resultNode.innerHTML = entry.description;
        }
}

function hylostest() {
    dojo.xhrGet( {
        url : "../../server/requestFile.php",
        handleAs : "json",
        preventCache: "true",
        handle : eObjectHandler
    });
}


From: Jared Jurkiewicz <jared.jurkiewicz@...>
To: dojo-interest@...
Sent: Thu, November 12, 2009 5:18:31 PM
Subject: Re: [Dojo-interest] Parsing JSON with DOJO

Post the code on how you are iterating.


On Thu, Nov 12, 2009 at 11:14 AM, viban Terence <vibanterence@...> wrote:

> Hallo Jared,
>
> thanks for your swift reply. I am doing a dojo.xhrGet and  using handleAs:
> "json". When i try to iterate the array as you suggest, all i get  is
> "undefined" and i do not unserstand what this means.
> Can this have something to do with the format of the json file here?.....i
> am really lost. I have checked the json in a json validator, and it seems to
> be fine. So i really have no idea what is going on. I thought switching from
> xml to json, would make things easy especially as i will be using dojo alot.
>
> Please just check to see if i am missing something, cause i know i am.
> Thanks again
>
>
> ________________________________
> From: Jared Jurkiewicz <jared.jurkiewicz@...>
> To: dojo-interest@...
> Sent: Thu, November 12, 2009 3:30:01 PM
> Subject: Re: [Dojo-interest] Parsing JSON with DOJO
>
> 1.)  If you're using dojo.xhrGet, why not just use handleAs: "json"  ?
> http://docs.dojocampus.org/dojo/xhrGet

>
> As it returns a JavaScript object (In this case it would be an array).
>
> To access data in it, you can just iterate the array as you would any
> javaScriot object and access attributes of it.  Eg:
>
> var i;
> for (i = 0; i < data.length; i++){
>     var entry = data[i];
>     console.log(entry.title);
>     console.log(entry.description);
>     // and so on.
> }
>
> -- Jared
>
>
> On Thu, Nov 12, 2009 at 7:03 AM, viban Terence <vibanterence@...>
> wrote:
>> Hello everyone,
>>
>> Been having problems parsing my dojo learning object. I have pasted a
>> section of what i get from the "responseText" from the server. y the way,
>> i
>> am getting this elearning objects from another server in xml format, and
>> then using a resource i found here () to get the json format. Each object
>> has categories which begin with a root (in this case it is just "lo"),
>> then
>> other categories are "general", "educational" etc. all this define
>> according
>> to the ieee lom standard. But that is all beside the point. The "general"
>> category has "title", "description" and i need to extract the information
>> here. Also the "content" category has "paragraph" nodes whose information
>> i
>> also need.
>> QUESTION, how do i parse a json file like this one to get the information
>> i
>> need. Do i need to create a data store? if yes how? do i need to do more
>> work on the server? I will appreciate all the answers i can get. This
>> issue
>> has slowed me down considerable.
>>
>> Here a section of the data. The categories are marked in blue.
>>
>>
>>
>> [{"lo":{"@attributes":{"path":"\/HyLOs\/content\/Data\/MIPv6\/MobilInter\/MobilInter","lastmod":"2007-11-13T22:17+0100"},"general":{"title":"Mobile
>> Internet","language":"en","description":"This course introduces protocols
>> and management schemes for mobility in the next generation Internet. It
>> presents current mobility extensions of IPv6 as designed to create a
>> realtimecompliant, secure mobile Internet. Starting from Mobile IPv6, the
>> basic","keywords":["Internet Protocol","MIPv4","MIPv6","Mobile
>> Internet","Standard"],"coverage":"Mobility Management in the Next
>> Generation
>>
>> Internet","structure":"Hierarchical","aggregationLevel":"1"},"educational":{"interactivityType":"Expositive","learningResourceType":"unit","interactivityLevel":"low","semanticDensity":"high","intendedEndUserRole":"Learner","context":"UniversitySecondCycle","typicalAgeRange":"20_30","difficulty":"medium","typicalLearningTime":"60","description":"Beim
>> Erstellen des Lernobjektes autmatisch erzeugter
>>
>> Eintrag.","language":""},"rights":"","lifecycle":{"status":"Draft","version":"1","contribute":[{"datetime":"2007-11-13T20:30+0100","role":"Author"},{"datetime":"2007-11-13T20:37+0100","role":"Author"},{"datetime":"2007-11-13T20:40+0100","role":"Author"},{"datetime":"2007-11-13T20:57+0100","role":"Author"},{"datetime":"2007-11-13T22:09+0100","role":"Author"},{"datetime":"2007-11-13T22:14+0100","role":"Author"}]},"content":{"section":"Mobility
>> Management in the Next Generation Internet","paragraph":"This course
>> introduces protocols and management schemes for mobility in the next
>> generation Internet. It presents current mobility extensions of IPv6 as
>> designed to create a realtimecompliant, secure mobile Internet. Starting
>> from Mobile IPv6, the basic end-to-endmobility managment protocol, we
>> discuss performace and security issues, as well as recentimprovements to
>> enhance mobility operations within the next generation Internet
>> protocol."},"bibList":""}}, (This is where the next learning object
>> begins)
>> {"lo":{"@
>>
>>
>> THANK YOU
>>
>>
>> _______________________________________________
>> FAQ: http://dojotoolkit.org/support/faq
>> Book: http://docs.dojocampus.org
>> Dojo-interest@...
>> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-interest@...
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest
< Prev | 1 - 2 | Next >