submit image button - POST data is not being passed

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

submit image button - POST data is not being passed

Post by crazytopu »

This is a bit strange. Does anyone know how to make it work. I have consulted this document and seems like I've done it right, still no luck.

http://uk2.php.net/variables.external


No data is being passed, newsLetter.php shows a complete blank page. I tried to echo something to test still nothing.

Note: it works fine when I use a button type submit. (i.e no image button).

Code: Select all

<form name="form_newsletter" method="post" action="newsLetter.php" onSubmit="return validateNewsLetter(form_newsletter);">
                                      <table width="100%" border="0">
                                        <tr>
                                          <td colspan="3"><span class="style22">Please enter your email address</span> </td>
                                        </tr>
                                        <tr>
                                          <td width="30%"><div align="right"><span class="style21 style22">News Letter </span></div></td>
                                          <td width="47%" valign="top"><label>
                                            <input name="news_email_txt" type="text" class="style13"  />
                                          </label></td>
                                          <td width="23%"><label>
                                            <input type="image" src="images/submit_newsletter.jpg" width="52" height="18" name="submit_newsletter" >
											
											
                                          </label></td>
                                        </tr>
                                      </table>
                                  </form>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What is your code for handling the submission?
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Thanks . here is it:

Code: Select all

<?
include('includes/DbConnector.php');

$connector= new DbConnector();

?>					
					
<?
					
					if(isset($_POST['submit_newsletter'])){
					
					/** test echo */
					//echo "clicked";
					
					/** for test purpose print email add*/
					//echo "your email address : ".$_POST['news_email_txt'];
					
					
					$insert = "INSERT INTO `newsletter` (`email`) 
                        VALUES ( 
                        
						
                        '".mysql_real_escape_string($_POST['news_email_txt'])."'    
                        
						)";
					
					
					//echo '<div>', htmlentities($insert), "</div>\n"; 
//echo '<br><div>', htmlentities($insert_to_member), "</div>\n"; 


if($insert_result = $connector->query($insert)) { 
  //echo "affected rows:", $connector->affected_rows(), "<br />\n"; 
 //echo "id:", $connector->insert_id(), "<br />\n"; 

	echo   '<div align="center">
 <span class=message> Thank you for subscribing to our newsletter </span></div> ';
			
} 
else{ 
  echo '<div align="center"><span class=error> There was an error, contact the technical support> ', $connector->mysql_error(), "</span></div><br />\n"; 
}
	
					
					}
					
					
?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Image submit buttons don't send their name, only the x and y value of the position you clicked on the image.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

How do websites use image buttons with forms and use PHP to process those forms then?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

If there is only one image button you can change

Code: Select all

if(isset($_POST['submit_newsletter'])){
to

Code: Select all

if(isset($_POST['x']) && isset($_POST['y'])){
Moved to client side
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Sorry, tried that. Didn't work. Any clue?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

why dont you print the POST values to see what is being submitted. Im sure you can managed a bit of general debugging yourself
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

JayBird wrote:Image submit buttons don't send their name, only the x and y value of the position you clicked on the image.
Not quite true.

Image buttons do pass their name as well as the X & Y co-ordinates. Browsers will send 'submit_newsletter.x' and submit_newsletter.y'. However, PHP interprets the '.' as a '_', so the POST parameters you're looking for are $_POST['submit_newsletter_x'] and $_POST['submit_newsletter_y'].
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Yes pickle, totally forgot about that. Im sure some browsers send different information, but cant find the info now. I know i had problems with is a couple of years back.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

:D Thanks pickle and JayBird you too.
Post Reply