#1
  1. No Profile Picture
    frequent PHP idiot
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    354
    Rep Power
    12

    Ajax PHP submission


    I'm having an issue. My code is is posting all the data to my php page however, it's not posting the form name to the page. In PHP I want to check what form this $_POST is coming from so I can decide what code to run. Any idea on how to include the form name in the $_POST set? Should I just add a hidden input that has the same name as my form ID?

    PHP Code:
      $("#projectInfo").submit(function(){
        
    /* code from above, changing form selector to "this" */
        
    $.post("projects/ajax.php", $(this).serialize(), function(data){
            if(
    data.error){
          $(
    '#error').css('display','block');
        }else {
            $(
    '#post_right').append(data);

                }      
            });    
        
    /* prevent browser default submit*/
          
    return false;
        }) 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2006
    Posts
    40
    Rep Power
    9
    Originally Posted by soupman99
    I'm having an issue. My code is is posting all the data to my php page however, it's not posting the form name to the page. In PHP I want to check what form this $_POST is coming from so I can decide what code to run. Any idea on how to include the form name in the $_POST set? Should I just add a hidden input that has the same name as my form ID?

    PHP Code:
      $("#projectInfo").submit(function(){
        
    /* code from above, changing form selector to "this" */
        
    $.post("projects/ajax.php", $(this).serialize(), function(data){
            if(
    data.error){
          $(
    '#error').css('display','block');
        }else {
            $(
    '#post_right').append(data);

                }      
            });    
        
    /* prevent browser default submit*/
          
    return false;
        }) 
    You need to pass the form name variable as hidden field to your php page
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    50
    Or, what I like to do, is take advantage of the fact that the name of the submit button is _POSTed. So, the name of the submit button effectively tells me the name of the form.

IMN logo majestic logo threadwatch logo seochat tools logo