Jump to content

Recommended Posts

Hi,

I want to submit a form using ajax ans jquery with two fields input text and file.

 

<script>
$(document).ready(
					function()
					{ 


						$('#basicinfofrm').ajaxForm(function() { 
																	url: ''+PN+'.php',
									type:'POST',
									data:'action=yes&'+frmFeilds,
									success: function(html)
									{  
alert(html);

									}

															    }).submit(); 
</script>
<form action='' method='post'>
    <label>name</label>
    <input type='text' name='txtname' />
    <input type='file' name  = 'txtfile' />
   <input type='submit' value='save' />
</form>

 

but is is not working...

can anyone tell me how to?

i don't want to refresh my page

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/261403-form-submit/
Share on other sites

hi,

Thanks for the reply,

I'm using two files

[/code]

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript" src="topnavscript/jquery.form.js"></script>

[/code]

one is for jquery and one is for ajax form. the problem is . form is being submit. but it give error for file that index is undefine. even i've given encryption too. like this

<form method=" post" action=""  onsubmit="return savebasicinfo(this);" enctype="multipart/form-data" id="basicinfofrm">

 

Please guide

thansk

Link to comment
https://forums.phpfreaks.com/topic/261403-form-submit/#findComment-1339502
Share on other sites

The "enc" in enctype is for encoding, not encryption.

 

Error messages like "undefined index: foo" have nothing to do with JavaScript or AJAX. They're just normal PHP error messages.

 

Post your full code and the entire message you're getting.

Link to comment
https://forums.phpfreaks.com/topic/261403-form-submit/#findComment-1339505
Share on other sites

Thanks for reply,

Here is my full code

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="topnavscript/jquery.form.js"></script>
<script>
function savebasicinfo(val)
{ 

$(document).ready(
					function()
					{ 


						$('#basicinfofrm').submit(function () {
														 $.ajax({
									url: 'process.php',
									type:'POST',
									data:'action=yes',
									success: function(html)
									{   alert(html);

									}
								});


															  });










					}
				);			
   
   return false;
}
</script>
<form method=" post" action=""  onsubmit="return savebasicinfo(this);" enctype="multipart/form-data" id="basicinfofrm">
                                	<input type="hidden" name="prnw_id" value="<?php echo $basicinfo['prnw_id']; ?>" />
                                	<table width="100%" cellpadding="10" cellspacing="10">
                                    	<tr><td>Name</td><td><input type="text" name="prnw_name" class="jointxtinputcss" 
                                        value="<?php echo $network->showoneoftwo($basicinfo['prnw_name'], 'Dummy Name'); ?>" /></td></tr>
                                        <tr><td>Email</td><td><input type="text" name="prnw_email" class="jointxtinputcss" 
                                        value="<?php echo $network->showoneoftwo($basicinfo['prnw_email'], 'email@transformbody.biz'); ?>" /></td></tr>
                                        <tr><td>Phone</td><td><input type="text" name="prnw_phone" class="jointxtinputcss" 
                                        value="<?php echo $network->showoneoftwo($basicinfo['prnw_phone'], '4535353453'); ?>" /></td></tr>
                                        <tr><td>City</td><td><input type="text" name="prnw_city" class="jointxtinputcss" 
                                        value="<?php echo $network->showoneoftwo($basicinfo['prnw_city'], 'Dubai'); ?>" /></td></tr>
                                        <tr><td>Country</td><td>
                                        <?php echo $network->selectbox('tbl_countries', 'countries_id', 'countries_name', 'name ="prnw_country"  class="joinslctinputcss"', $basicinfo['prnw_country']); ?>
                                       </td></tr>
                                        <tr><td>Date of Birth</td><td><input type="text" name="prnw_dateofbirth" class="jointxtinputcss" <?php echo $network->showoneoftwo($basicinfo['prnw_dateofbirth'], '2012-02-02'); ?> /></td></tr>
                                        <tr><td>Gender</td><td><?php echo $network->selectbox('tbl_job_gender', 'gen_id', 'gen_name', 'name ="prnw_gender"  class="joinslctinputcss"', $basicinfo['prnw_gender']); ?></td></tr>
                                        <tr><td>Image</td><td><input type="file" name="prnw_image" class="jointxtinputcss" /><br>
                                        					  <img src="images/<?php echo $network->showoneoftwo($basicinfo['prnw_image'], 'dummy.png'); ?>" width="120" alt="sani"  />
                                                              <input type="hidden" name="txtoldimage" value="<?php echo $network->showoneoftwo($basicinfo['prnw_image'], 'dummy.png'); ?>" />
                                        </td></tr>
                                        
                                        <tr><td>Address</td><td><textarea name="prnw_address" class="jointxtinputcss" ><?php echo $network->showoneoftwo($basicinfo['prnw_address'], 'Main Bulevard, Albersha 1, Dubai, UAE'); ?></textarea></td></tr>
                                        
                                        <tr><td> </td><td><input type="submit" name="txtbasicinfosubmit" value="Save" class="joinsubmitcss" /></td></tr>
                                        
                                    </table>
                                </form>

 

and my process.php file has following code

<?php

$prnw_id			=	'';
	$prnw_name 			=	'';
 	$prnw_email 		=	'';
 	$prnw_phone 		=	'';
 	$prnw_country		=	'';
 	$prnw_city			=	'';
	$prnw_dateofbirth	=	''; 	
	$prnw_gender		=	'1';
	$prnw_address		=	'';
	$prnw_image			=	'';
	$txtoldimage		=	'';



	if(!empty($_FILES["prnw_image"]["name"]))	
	  {	
		  	$accept = array('jpg','png','gif','bmp');
			$extension = substr($_FILES['prnw_image']['name'],strrpos($_FILES['prnw_image']['name'],'.')+1);

			if(in_array($extension,$accept))
			{
			  $image->load($_FILES["prnw_image"]["tmp_name"]);
			  $image->resizeToWidth(120);
			  $random_digit	=	md5(rand(0000,9999));
			  $filename		=   $random_digit.$_FILES["prnw_image"]["name"];
		      $image->save("../../../network/images/profile/thumb/" . $filename);
			  $prnw_image	=   $filename;
			}


	 }else { $prnw_image	=	$txtoldimage;}

print_r($_POST);
?>

 

following error i'm getting:

 

 

<br />

<b>Notice</b>:  Undefined index: prnw_image in <b>C:\Program Files\VertrigoServ\www\demo\process.php</b> on line <b>491</b><br />

 

 

hope everything is clear now.

please guide...

Link to comment
https://forums.phpfreaks.com/topic/261403-form-submit/#findComment-1339509
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.