tags:

views:

59

answers:

2

Hi. I hope someone could help me.

When i load an external php that generates a set of fields, i have no problems, but then i send the generated form, i can not access the vars.

There is the code i user:

For load the external file:

      $.ajax({

    type: "POST",
    url: "product-insert.php",
    contentType: "application/x-www-form-urlencoded",
    global: true,
    processData:true,
    dataType: 'html',
    data: {num_filas: $("#num_filas").val()},

    success: function(html){
             $("#destino").html(html);
             alert(html);
             str = $("ofertas").serialize();
    },

    error: function(){
    },

    complete: function(){
    }
});


  <form action="ofertas.php" method="post" enctype="multipart/form-data" name="form-ofertas" id="ofertas" >

  <div id="destino"></div>

The file loaded have this code:

echo '<input name="campo" type="hidden" value="valor" />';

and the php file that receive the form have this code:

die("campo: ".$_REQUEST['campo']);

I really will appreciate a lot the help.

Thnx in advance.

Yannick

A: 

Based upon your comment, you're checking for $_POST['campo'] despite the fact that your <form> tag's method is a GET request. You should instead check the value of $_GET['campo'] (or $_REQUEST['campo']).

Matt Huggins
@Matt Hugginsi've tried, but still not working :(I think problem is that the values of the form dinamically loaded are not sent when click the submit button.Maybe if i send the form using jquery will work?Thnx in advance.
SauronZ
Do you have a `</form>` tag? You didn't include it in your question if you do.
Matt Huggins
A: 

I'm guessing partially off comments here, your form looks like this:

<form action="ofertas.php" method="get" enctype="multipart/form-data" 
 name="form-ofertas" id="ofertas"> 
  <div id="destino"></div> 
</form> 

Your method is GET, which won't give you what you're after if you're looking for the values in the POST collection, which $_POST does. Just change the method on your form to method="post" to get this working correctly, otherwise use $_GET on the PHP side, if a GET is what you're actually after.

For a good discussion of GET vs POST, take a look here:
When do you use POST and when do you use GET?

Nick Craver
@Nick CraverI have updated the code, but still not working.The mistake of POST and GET was due to so many changes :)
SauronZ
@SauronZ - now you have 2 `success` functions defined...need that not to be the case, remove the first and put the `alert()` in the second, what's the result then?
Nick Craver
@Nick Craver - Removed in code and in example, but still the same.I really don't know what can be happening :(
SauronZ
@SauronZ - I don't know what's run from the info provided...any chance there's a page I can hit?
Nick Craver
@Nick Craver- http://ulzama.es/admin/ofertas.phpn=1 - User/pass: Nick - Press the second Radio button and continue. Then you have the form. Simply enter 2 in the last field and click Añadir productos, it will load the external field. Really thnx for your patience
SauronZ
@Nick Craver- i have simplified the include file, but nothing....
SauronZ
@SauronZ - I had to run for dinner, can't login now though, let me know if you can re-enable it.
Nick Craver