Here is the jQuery ajax part
function submitTic(){
$('#form').html("<img src='/img/pleasewait.gif' />");
namev = $("input[name=name]").val();
console.log("Namev: "+namev);
purpv = $("input[name=purp]").val();
console.log("Purpv: "+namev);
detailsv = $("textarea[name=details]").val();
console.log("Detailsv: "+detailsv);
tov = "<? echo $_GET['t'];?>";
console.log("Tov: "+tov);
$.ajax({
url:"http://<?echo $location;?>/modules/Ticket/new/submit.php",
type:"POST",
data:{
name: namev,
purp: purpv,
details: detailsv,
to: tov
}
})
.always(function(response){
$('#form').html(response);
});
}
The form looks like this
<div id='form'>
<form>
<table>
<tr><td class='left'>*Name:</td><td><input type='text' name='name' size='40' required="required"></td></tr>
<tr><td class='left'>*Purpose:</td><td><input type='text' name='purp' maxlength="100" size='40' placeholder="Example: <?echo $placeholder;?>" required="required"></td></tr>
<tr><td class='left'>*Details:</td><td><textarea name="details" cols="45" rows="10" maxlength="1000" required="required"></textarea></td></tr>
<tr><td colspan='2' align='center'><input type='button' onclick="submitTic();" value="Submit Ticket" id='submit' ></td></tr>
</table>
<span id='reqcap'>*Required</span>
<input type="hidden" name="for" value="<? echo $_GET['t'];?>"/>
</form>
</div>
My problem is that when I submit the form and catch it on the other end, the only piece in the $_POST array is the "to" variable. I've tried moving the jQuery part to the data, I've tried everything short of hardcoding the variables because that would defeat the purpose of the form.
When in console, I can pull it using the $.val, but I can not assign to variable. I have no idea what's going on. Anyone have any ideas?
Well judging by that code, you're trying to get the values from your form, but you've replaced the entire form with a loading image so there are no values to get. Try doing
namev = $("input[name=name]").val();
console.log("Namev: "+namev);
purpv = $("input[name=purp]").val();
console.log("Purpv: "+namev);
detailsv = $("textarea[name=details]").val();
console.log("Detailsv: "+detailsv);
tov = "<? echo $_GET['t'];?>";
$('#form').html("<img src='/img/pleasewait.gif' />");
instead. Notice the
$('#form').html("<img src='/img/pleasewait.gif' />");
is now the last thing to be done, not the first