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,671
    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(); ?!

  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



Recent Articles