CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 AJAX and record form problem

Print topic Send  topic

Author Message
matik

Posts: 57
Posted: 05/18/2007, 2:52 PM

Hi,

I have successful use Ajax for creating search table and on that table I have add links for edit data.

When I click on link I get record form below search results (without refreshing page) but when I try to submit changes I am always redirected to edit.php page (edit.php is where search results and edit form are).

How can I submit changes or add new records without redirecting?

Thank you,
Matik
View profile  Send private message
Damian Hupfeld
Posted: 05/18/2007, 3:08 PM

set the "return page" in your record grid properties.

"matik" <matik@forum.codecharge> wrote in message
news:5464e201ae477e@news.codecharge.com...
> Hi,
>
> I have successful use Ajax for creating search table and on that table I
> have
> add links for edit data.
>
> When I click on link I get record form below search results (without
> refreshing
> page) but when I try to submit changes I am always redirected to edit.php
> page
> (edit.php is where search results and edit form are).
>
> How can I submit changes or add new records without redirecting?
>
> Thank you,
> Matik
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

matik

Posts: 57
Posted: 05/18/2007, 3:39 PM

I have index page where using AJAX I make search and display record form from edit.php

But when I click submit btn to submit changes I am redirected (browser url) to edit.php page or any other page I setup In “return page”.
View profile  Send private message
Damian Hupfeld
Posted: 05/18/2007, 3:43 PM

The page has to return somewhere - if you want it to return to itself either
clear \this value or set it to that filename - or I am completely
misunderstanding your question.

"matik" <matik@forum.codecharge> wrote in message
news:5464e2b1b5e346@news.codecharge.com...
>I have index page where using AJAX I make search and display record form
>from
> edit.php
>
> But when I click submit btn to submit changes I am redirected (browser
> url) to
> edit.php page or any other page I setup In "return page".
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

lwismanuel


Posts: 39
Posted: 05/19/2007, 11:04 AM

Matik, set the action in your html form tag as follow: action="javascript:;" and the submit button onClick="sub(this.form,'your url goes here');"
That is going to prevent it from reloading the page you are posting to.
Then you must collect each element of the form to be posted to the desire page using Ajax.
function getFormValues(form){  
	form = $(form);  
    var field = "";  
    var value = "";  
    var valueString = "";  
    var replaceID = "";  
    var parentNode = form.parentNode;  
  
    for (var i = 0; i < form.elements.length; i++) {  
        var field = form.elements;  
  
        if (!field.disabled) {  
            filedName = encode(field.name);  
  
            if (field.type == 'select-one') {  
                if (field.selectedIndex > -1) {  
                    value = field.options[field.selectedIndex].value;  
                }  
            } else {  
                value = field.value;  
            }  
  
            valueString += ((i) ? '&' : '') + field.name + '=' + encode(value);  
        }  
    }  
    return valueString  
}  
function encode( uri ) {  
    if (encodeURIComponent) {  
        return encodeURIComponent(uri);  
    }  
  
    if (escape) {  
        return escape(uri);  
    }  
}  
function $() {  
    var elements = new Array();  
  
    for (var i = 0; i < arguments.length; i++) {  
        var element = arguments;  
  
        if (typeof element == 'string')  
            element = el(element);  
  
        if (arguments.length == 1)  
            return element;  
  
        elements.push(element);  
    }  
  
    return elements;  
}  

Assuming that you are using POST for your form submition then use this funtion:

  
function sub(f,url,targetElm)	{  
		var parameters = getFormValues(f);  
		makePOSTRequest(url,parameters,targetElm);  
}  
  
function makePOSTRequest(url,parameters,targetElm) {  
	var Req = xmlHttp(); // Matik, chage the xmlHttp() function to whatever object return your XMLHttpRequest()  
	var element = document.getElementById(targetElm);  
	element.innerHTML = '<p><em>Loading ...</em></p>';  
   Req.onreadystatechange = function () {  
   								if (Req.readyState == 4) {  
      								if (Req.status == 200) {  
         								result = Req.responseText;  
         								element.innerHTML = result;              
      								} else {  
         									alert('There was a problem with the request.');  
      										}  
   								}  
							}  
   Req.open('POST', url, true);  
   Req.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");  
   Req.setRequestHeader("Content-length", parameters.length);  
   Req.setRequestHeader("Connection", "close");  
   Req.send(parameters);  
}
View profile  Send private message
matik

Posts: 57
Posted: 05/19/2007, 3:46 PM

Thank you,

I will learn a lot from this code.

I was thinking to use record form created with CCS so I don’t have manually to collect and manage data.

I will put test files online tomorrow.

Matik
View profile  Send private message
lwismanuel


Posts: 39
Posted: 05/19/2007, 4:38 PM

Quote :
I was thinking to use record form created with CCS so I don’t have manually to collect and manage data.
You do not have manually to collect and manage data. You can use the form generated by CCS and just change the the part in the form that I told you.
View profile  Send private message
matik

Posts: 57
Posted: 05/20/2007, 6:32 AM

Can you please download project files from:

http://www.urovica.info/demo/ajax/index.php

and edit them. Only record form is not working. Searching and navigation is working in without refreshing.

I just can make record form to work.

Thank you.

Matik
View profile  Send private message
matik

Posts: 57
Posted: 05/23/2007, 1:58 AM

lwismanuel,
I alwayst get this error:

Error: form.elements has no properties

I have add this function for xmlHttp():

function GetXmlHttpObject()  
{  
var xmlHttp=null;try  
 {  
 // Firefox, Opera 8.0+, Safari  
 xmlHttp=new XMLHttpRequest();  
 }  
catch (e)  
 {  
 // Internet Explorer  
 try  
  {  
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
  }  
 catch (e)  
  {  
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
  }  
 }  
return xmlHttp;  
}  

Any idea?

Thank you.
View profile  Send private message
username

Posts: 24
Posted: 09/09/2007, 9:32 AM

Thanks
does any body have any example for ajax in CCS php
please give me poject example for ajax CCS php

amir.email [at]yahoo.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.