PHP Submit Form without refreshing.

Associate
Joined
10 May 2007
Posts
541
Location
Kent
I have a form that I would like to submit to the same page, but since there are about 150+ records, if you were to click half way down and submit that form, it would reload the page and take you to the top.

So I was thinking of a way to submit the form without having to go through this scenario each time, I think I would need AJAX, not sure though.

Code:
<form name="upload2" action="import.php" method="post">
<input name="barcode" type="hidden" value=<?php echo( $row['barcode'] ); ?> readonly="true"><input name="accno" type="hidden" value=<?php echo( $row['accno'] ); ?> readonly="true">
<input name="file_name" type="hidden" value="<?php echo "$file_name"; ?>" readonly="true">
<input type="hidden" name="webcode" value="<? if ($row['webcode'] == 'EURO'){ echo $row['webcode'] == NULL;} else { echo $row['webcode'];}?>">
<input <? echo $disabled;?> onClick="return confirmation()"  type="submit" name="Send" value="Send" /></form>

As you can see, the onClick calls to a JS function which is a basic confirm message:
Code:
function confirmation() {
  if (confirm("Are you sure you want to send?")) {
    return true;	
    }
	else{
	return false;
	}
}

So, ideally the code could be put here I suppose. if true, it submits the form without refresh. I've tried googlin' a bit and a lot of people are saying AJAX. But just wanted to see if anyone knew of a work around or anything.

Cheers guys
 
That'll work nicely, although in the code they give you it's much easier to do $(#form").serialize() rather than create a string yourself which contains each field for every form you want to put this on.
 
Back
Top Bottom