ballhogjoni Posted August 4, 2007 Share Posted August 4, 2007 How can I make an image a submit button using the following: <input type="image" src="/images/registermyaccount.gif" value="register" name="register"/> right now it is not submitting like a type="submit" button would. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/ Share on other sites More sharing options...
AndyB Posted August 4, 2007 Share Posted August 4, 2007 click it ... and check $_POST['register_x'] is set Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315718 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 no it doesn't echo anything. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315723 Share on other sites More sharing options...
AndyB Posted August 4, 2007 Share Posted August 4, 2007 What I explained was how to detect an image submit with php. Show some of your code. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315724 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 hm, could be simpler than that. Is the button inside FORM tags? -BSIS Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315725 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 Of couse I have an echo $_POST['register']; to see if the name attribute is being passed. <html> <head> <title>Register for FREE Shopping Cart</title> <link href="style_sheet.css" rel="stylesheet" media="screen"> </head> <body> <table align="center"> <tr> <td> <fieldset><legend>Register Here</legend> <table> <tr> <td> <form action="register.php" method="post"> <table> <tr> <td> Username: </td> <td> <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /> </td> </tr> <tr> <td> Password: </td> <td> <input type="password" id="password" name="password" size="32" value="" /> </td> </tr> <tr> <td>Re-password: </td> <td><input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /></td> </tr> <tr> <td>Email: </td> <td><input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /></td> </tr> <tr> <td colspan="2" align="center" class="style7"> You must confirm the email address before activating your account. </td> </tr> <tr> <td colspan="2" align="center"> <input type="image" src="/images/registermyaccount.gif" value="register" name="register"/> </td> </tr> </table> </form> </td> </tr> </table> </fieldset> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315727 Share on other sites More sharing options...
AndyB Posted August 4, 2007 Share Posted August 4, 2007 We need to see the script that processes the form data, i.e. register.php It's NOT $_POST['register']. It's either $_POST['register_x'] or $_POST['register_y']. Image submits work like image maps - they give the x and y coordinates of where the image was clicked relative to the top left corner. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315730 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 o snap. I don't know anything about maps. is there a good tutorial to learn from. I thought it worked just like 'button' and 'submit'. My script doesn't do anything until the $_POST['register'] is set. I.E. if (isset($_POST['register'])) { //run the script } so basically i need to change the $_POST['register_x'] or $_POST['register_y']? Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315733 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 If i echo echo $_POST['register_x']; echo $_POST['register_y']; it displays differnt numbers every time I click the image. What do I do now? Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315742 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 if either value is set, the button has been clicked. what you're seeing is the x and y coordinates of where the button is clicked. -BSIS Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315743 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 ok so I have changed my if statement to look like this: if(isset($_POST['register_y'])) {} But now when I click the image my screen just goes blank. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315745 Share on other sites More sharing options...
AndyB Posted August 4, 2007 Share Posted August 4, 2007 we need to see register.php - that's where you have the problem. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315753 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 <?php require_once('db.php'); include('functions.php'); $Username = $_POST['username']; $Username_checked = strip_tags($Username); if(isset($_POST['register'])) { if($Username_checked!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $Username_checked)==TRUE && checkUnique('Email', $_POST['email'])==TRUE) { $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($Username_checked)."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error()); $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($Username_checked)."'") or die(mysql_error()); if(mysql_num_rows($getUser)==1) { $row = mysql_fetch_assoc($getUser); $headers = 'From: webmaster AT realfinancialsuccess.com' . "\r\n" . 'Reply-To: webmaster AT realfinancialsuccess.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = "Activation email from Free Cart"; $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.realfinancialsuccess.com/freeCart/confirm.php?ID=".$row['ID']."&key=".$row['Random_key']." Thank you for joining"; if(mail($row['Email'], $subject, $message, $headers)) {//we show the good guy only in one case and the bad one for the rest. $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.'; } else { $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine'; } } else { $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.'; } } else { $taken = mysql_query("SELECT Username FROM users WHERE Username = '{$Username_checked}'") or die(mysql_error()); $username_taken = mysql_fetch_array($taken) or die(mysql_error()); if ($username_taken) { $error = 'The Username is already taken or you have illegal characters for your username. The Username may only contain numbers, letters, and underscores.'; } else { $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match'; } } } ?> <?php if(isset($error)){ echo $error;}?> <?php if(isset($msg)){ echo $msg;} else {?> Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315754 Share on other sites More sharing options...
mrjcfreak Posted August 4, 2007 Share Posted August 4, 2007 put print_r($_POST); at the top of your receiving PHP and see what comes out. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315757 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 I see this in there: if(isset($_POST['register'])) should be if(isset($_POST['register_x'])) Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315760 Share on other sites More sharing options...
AndyB Posted August 4, 2007 Share Posted August 4, 2007 if(isset($_POST['register'])) - No, no, no! if (isset($_POST['register_x'])) - just as explained already at least three times Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315763 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 AndyB As I was saying when I change if(isset($_POST['register'])) to if (isset($_POST['register_x'])) nothing happens. Its like the page goes blank. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315766 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 the page is probably going blank due to code after the if. For sure, if you use $_POST['buttonname'] without an _x or _y, you'll get nothing. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315768 Share on other sites More sharing options...
AndyB Posted August 4, 2007 Share Posted August 4, 2007 Then you have a logic or database problem with the code that follows. Checking that an image button is clicked requires you verify that either an x or y coordinate has been passed. That x and y stuff is actually the same basis that makes an html image map detect where it's been clicked. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315769 Share on other sites More sharing options...
ballhogjoni Posted August 4, 2007 Author Share Posted August 4, 2007 Ok you are right I echoed the register_x and it appeared but the rest of the code didn't do anything. Do you think it has something to do with the functions? Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315770 Share on other sites More sharing options...
BlueSkyIS Posted August 4, 2007 Share Posted August 4, 2007 I don't see anything obvious, but I'd be wary of an if (mail()) I'd step through, putting echo() here and there, hack away, etc. etc. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315773 Share on other sites More sharing options...
The Saint Posted August 4, 2007 Share Posted August 4, 2007 <input src="IMAGEGOESHERE" name="NAME HERE" type="image" id=" alt="Optional" onclick="doSubmit('submitlinkhere');" /> this should work Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315787 Share on other sites More sharing options...
dbo Posted August 5, 2007 Share Posted August 5, 2007 I'd have to suggest against this approach. You're relying on javascript to handle your form submission. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-315796 Share on other sites More sharing options...
Crew-Portal Posted August 6, 2007 Share Posted August 6, 2007 use (ini_set 'error_handling' , '1'); Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-316640 Share on other sites More sharing options...
ballhogjoni Posted August 7, 2007 Author Share Posted August 7, 2007 I don't see anything obvious, but I'd be wary of an if (mail()) I'd step through, putting echo() here and there, hack away, etc. etc. What should I do instead. I don't fully understand this quote. Quote Link to comment https://forums.phpfreaks.com/topic/63353-image-submit-button/#findComment-317653 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.