Posting forms with Ajax and PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Posting forms with Ajax and PHP

    Hi Guys

    I have hit a bit of a snag.

    I will explain the setup. Firstly once i have loaded the web page, the form is then fetched and loaded automatically via AJAX without the page refreshing and loads the form into a div tag on my web page....this works 100%

    After filling the form and i click on the send button, AJAX then posts the data to an external php file where the info is processed and added to the database.... this also works 100% but i have one problem. If the user uses & or & in any of the form fields, the info for just that field is not sent via AJAX and reads as a NULL value.

    I know how to over come this with PHP but not Javascript.
    Simple. info sent -> Ajax / Javascript -> PHP -> DB

    Here is the code used to post.

    Code:
     <script type="text/javascript" >
    	$(function()
    		{
    		$(".update").click(function()
    			{
    			var user_email = $("#user_email").val();
    			var user_url = $("#user_url").val();
    			var user_mobile = $("#user_mobile").val();
    			var land_line = $("#land_line").val();
    			var address = $("#address").val();
    			var facebook_group = $("#facebook_group").val();
    			var facebook_profile = $("#facebook_profile").val();
    			var uid = $("#uid").val();
    			var doupdate = $("#doupdate").val();
    			
    			var dataString = 'user_email='+user_email+ '&user_url='+user_url+ '&user_mobile='+user_mobile+ '&land_line='+land_line+ '&address='+address+ '&facebook_group='+facebook_group+ '&facebook_profile='+facebook_profile+ '&uid='+uid+ '&doupdate='+doupdate;
    			
    			$.ajax(
    					{
    					type: "POST",
    					url: "<?php echo bloginfo('template_directory'); ?>/inc/insertajax.php?faction=update_profile",
    					data: dataString,
    					cache: false,
    					success: function()
    						{
    						ajax_saveContent('profile_contact_information','<?php echo bloginfo('template_directory'); ?>/inc/external_1.php?action=profile_contact_information');
    						}
    					});
    			return false;
    			});
    		});
    	</script>
    Now you will notice "var dataString" carries all the info of each form field and they are seperated by the & sign. This is where the problem is but i have no idea how to fix it.

    Can anyone help?
    sigpic

    |~~Dont forget to say thanx~~|

    #2
    i think i managed to figure it out, it seems to work

    Code:
    var about_me1 = $("#about_me").val();
    			if (about_me1==null)
    				{
    				var about_me = "";
    				}
    			else
    				{
    				var about_me2 = about_me1.replace(/&/g, "and"); //g = searches for all & signs
    				var about_me = about_me2.replace(/'/g, "\"");
    				}
    sigpic

    |~~Dont forget to say thanx~~|

    Comment

    Working...
    X