www.webdeveloper.com
Results 1 to 4 of 4

Thread: can not sebd form data with ajax to php

  1. #1
    Join Date
    Jan 2014
    Posts
    10

    Question can not sebd form data with ajax to php

    HI ALL!!!
    I`m new on this forum and in JS too...
    please help me...

    I`m trying to send form data with POST via AJAX to PHP
    I`m using JQXWidgets...

    I have created a JQXwibdow

    HTML Code:
    div id="add_new_user">
    	<div id="add_new_userHeader">
        	<span>
            	<img src="img/icons/add.png" style="margin-right: 15px;">
                <span id="add_new_userHead_name"></span>
    		</span>
    	</div>
        <div id="add_new_userContent" style="overflow: hidden;">
            <form method="post" id="add_user" autocomplete="off">
                <input type="text" id="add_username" style="margin:5px;"/>
                <input type="password" id="add_psw" style="margin:5px;"/>
                <input type="password" id="ret_add_psw" style="margin:5px;"/>
                <div id="company" style="margin:5px;"></div>
                <div id="group" style="margin:-33px 0 0 185px;"></div> 
                <div id='add_birth' style="margin:-28px 0 0 360px; float:left;"></div>    
                <input type="text" id="add_fname" style="margin:10px 5px 5px;"/>
                <input type="text" id="add_mname" style="margin:5px;"/>
                <input type="text" id="add_lname" style="margin:5px;"/>
                <div id="selectiongend" style="float: left;font-size: 13px;font-family: Verdana;margin:5px;">
                    <div id='add_gend_man' style="margin:5px;"><span id="add_gendman"></span></div>
                    <div id='add_gend_woman' style="margin:-22px 0 5px 60px;"><span id="add_gendwoman"></span></div>
                </div>            
                <input type="submit" style="margin:5px; float:left;" id="add_new_usrbtn" onClick="_addEventListeners()"/>
            </form>
        </div>
    </div>
    with the button click function I`m trying to send this form data to PHP talk file...
    I need this file to talk over php OOP and js

    Code:
    $('#add_new_usrbtn').click(function (e) {
    	e.preventDefault();
    	var psw2 = document.getElementById('ret_add_psw').value;
    	dataString = 'action=' + 'newuser' + '&usr=' + $('add_username').val() + '&psw=' + $('add_psw').val() + '&fname=' + $('#add_fname').val()  + '&lname=' + $('add_lname').val() + '&mname=' + $('add_mname').val() + '&' + $('form#add_user').serialize(e);
    	$.ajax({
    		type: "POST",
    		url: "system/talk.php",
    		data: dataString,
    		dataType: "html",
    		cache: false,
    		beforeSend: function(data){
    			alert(data);},
    		error: function(data){
    			alert(data);},
    		success: function(data){
    			alert(data);
    		}													   
    	}); 
    	return false;  
    });
    and in talk.php I have this code

    PHP Code:
    if ($_POST['action'] === 'newuser')
                {
                        
    $username $_POST['usr'];
                        
    $password $_POST['psw'];
                        
    $company $_POST['company'];
                        
    $birth $_POST['add_birth'];
                        
    $group $_POST['group'];
                        
    $fname $_POST['add_fname'];
                        
    $mname $_POST['add_mname'];
                        
    $lname $_POST['add_lname'];
                        if (
    $_POST['add_gend_man'] = true){
                            
    $gender 'M';
                        } elseif(
    $_POST['add_gend_woman'] = true){
                            
    $gender 'F';
                        } else { echo 
    'მოხდა შეცდომა';}
                    
    $salt $account->salt_code();
                    
    $email_code $email->email_code();
                    
    $result $account->creat_acc($username,$password,$company,$birth,$group,$fname,$mname,$lname,$gender,$salt,$email_code);
                    echo 
    $result;
                } 
    but in php data is 0

    when I`m trying to echo any of them
    ex. $fname
    it said me that the variable is null
    and I can not write nullable variable`s value in my db

    please help me

    what is wrong in my code???
    I do not understand...

    please help me!!!

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    Code:
    var psw2 = document.getElementById('ret_add_psw').value;
    	dataString = 'action=' + 'newuser' + '&usr=' + $('#add_username').val() + '&psw=' + $('#add_psw').val() + '&fname=' + $('#add_fname').val()  + '&lname=' + $('#add_lname').val() + '&mname=' + $('#add_mname').val() + '&' + $('form#add_user').serialize(e);
    and why document.getElementById('ret_add_psw').value; instead of $('#ret_add_psw').val(); ?!
    signature under construction

  3. #3
    Join Date
    Jan 2014
    Posts
    10

    Question

    Quote Originally Posted by Padonak View Post
    Code:
    var psw2 = document.getElementById('ret_add_psw').value;
    	dataString = 'action=' + 'newuser' + '&usr=' + $('#add_username').val() + '&psw=' + $('#add_psw').val() + '&fname=' + $('#add_fname').val()  + '&lname=' + $('#add_lname').val() + '&mname=' + $('#add_mname').val() + '&' + $('form#add_user').serialize(e);
    and why document.getElementById('ret_add_psw').value; instead of $('#ret_add_psw').val(); ?!
    #ret_add_psw it is Repeat Password so it is not much means...

    I`m not sending this value to php
    I`m cgecking it in js...

    but I have another problem

    I do not understand
    ajax is not sending or php is not receiving???
    why it said me that the values are null????

  4. #4
    Join Date
    Jan 2014
    Posts
    10
    The problem is solved!!!

    thank you all!!!
    I add all input tags in empty DIV tags
    and after that jquery serialize is orking fine...

    thank....!!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14101 seconds
  • Memory Usage 2,898KB
  • Queries Executed 15 (?)
More Information
Template Usage (36):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates