954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dynamic Form POST

Hi guys i was wondering if you guys could let me know how i can post a form field using jquery and then be declared in a variable after post.

The code for the html:

<table cellpadding="0" cellspacing="0">
            <tr>
        		<td></td>
                <td>Name:</td>
                <td>Email:</td>
            </tr>
            <tr>
            	<td><label for=fri accesskey=f>Friend 1</label></td>
                <td class="tablePadding"><input name="friname[]" type="text" id="friname" class="friname" size="25" value="" /></td>
                <td><input name="friemail[]" type="text" id="friemail" class="friemail" size="25" value="" /></td>
            </tr>
            <tr>
            	<td><label for=fri accesskey=f>Friend 2</label></td>
                <td class="tablePadding"><input name="friname[]" type="text" id="friname" class="friname" size="25" value="" /></td>
                <td><input name="friemail[]" type="text" id="friemail" class="friemail" size="25" value="" /></td>
            </tr>
            <tr>
            	<td><label for=fri accesskey=f>Friend 3</label></td>
                <td class="tablePadding"><input name="friname[]" type="text" id="friname" class="friname" size="25" value="" /></td>
                <td><input name="friemail[]" type="text" id="friemail" class="friemail" size="25" value="" /></td>
            </tr>
            </table>


It gets posted to contact.php

here is the php contact.php file

$friname    = $_POST['friname'];
	
	foreach ($friname as $item) {
		print $item."";	
	}


Here is the jquery for the post

$('#contactform').submit(function(){
	
		var action = $(this).attr('action');
		
		$("#message").slideUp(750,function() {
		$('#message').hide();			
		
		
		$.post(action, { 
			name: $('#name').val(),
			email: $('#email').val(),
			friname: $('#contactform input[name="friname[]"]').val(),
			friemail: $('.friemail').val(),
			comments: $('#comments').val(),
			verify: $('#verify').val()
		},
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()}); 
				if(data.match('success') != null) $('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});


Thank you if you guys can help.

Thanks,
Marais

marases
Junior Poster in Training
87 posts since Sep 2010
Reputation Points: 21
Solved Threads: 7
 

are you having trouble sending/submitting all the fields? If so, try:

$('#contactform').submit(function(){
	
		var action = $(this).attr('action');
		
		$("#message").slideUp(750,function() {
		$('#message').hide();			
		
		// http://api.jquery.com/serialize/
		$.post(action, $('#contactform').serialize(),
			function(data){
				document.getElementById('message').innerHTML = data;
				$('#message').slideDown('slow');
				$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()}); 
				if(data.match('success') != null) $('#contactform').slideUp('slow');
				
			}
		);
		
		});
		
		return false; 
	
	});
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
 

thanks you soo much, that really helped. As you can tell im a php coder not a jquery coder. HEHE

Thanks,
Marais

marases
Junior Poster in Training
87 posts since Sep 2010
Reputation Points: 21
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: