TeddyKiller Posted May 6, 2010 Share Posted May 6, 2010 The form in the code below, submits. Although it doesn't go through the validation? I don't understand why. I'm pretty sure the form is submitting. It has no reason not to... Can anyone point me in the right direction? <script> function submitform(FORM) { document.forms[FORM].submit(); } </script> <?php if(isset($_POST['submit'])) { if($user->credits < '1000') { echo '<span style="color:#e11919;>Not enough credits!</span>'; } else { $time = time(); $query = mysql_query("INSERT INTO `featured_member` (user_id, views, date) VALUES ('$user->id', '0', '$time')"); if($query) { $credits = $user->credits - 1000; $query = mysql_query("UPDATE `users` SET credits = '$credits' WHERE `id` = '$user->id'"); } } } echo '<div style="text-align:left;"> <form action="" method="post" name="feature"> <input type="hidden" name="submit" value="submit" /> <a href="#" onclick="javascript: submitform(\'feature\')">Feature Me!</a> (1000 Credits!) </form> </div>'; ?> Quote Link to comment Share on other sites More sharing options...
siric Posted May 6, 2010 Share Posted May 6, 2010 There is no need to js. In the <form> line use <FORM name="feature" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > This will cause the page to reload itself. Also where do you load the variables user->credits which is used in this line ? if($user->credits < '1000') { Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 6, 2010 Share Posted May 6, 2010 This is probably because your hidden input is named submit. In JavaScript, form.submit() is normally a function that submits the form. However, in some (or all?) browsers, form.ident will also refer to controls in your form. For example, if you have a text input on your form called first_name, in your JavaScript you can use: alert( form.first_name.value ); Now like I said, form.submit() should be a function. But you've named a hidden input submit. So now form.submit refers to a hidden input and form.submit() is probably a JavaScript error. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 6, 2010 Author Share Posted May 6, 2010 There is no need to js. In the <form> line use It's an href submit.. so there is no button. Also where do you load the variables user->credits which is used in this line ? It's part of an check_user function called at the top of the page to get all information from the users table based on the current logged in user. Though that isn't the problem. I changed the name of the hidden input field, to "becomefeatured" and changed the $_POST so that it matches. This never fixed the problem. Do I need a hidden field anyway? Any help... ? Thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2010 Share Posted May 6, 2010 If that's the whole form and there is no actual form data being submitted, there is no point in using a form. Just use a href link by itself. Quote Link to comment Share on other sites More sharing options...
phpchamps Posted May 6, 2010 Share Posted May 6, 2010 Below is the modified code...check <script> function submitform() { alert("A"); document.feature.submit(); } </script> <?php if(isset($_POST['submit'])) { if($user->credits < '1000') { echo '<span style="color:#e11919;>Not enough credits!</span>'; } else { $time = time(); $query = mysql_query("INSERT INTO `featured_member` (user_id, views, date) VALUES ('$user->id', '0', '$time')"); if($query) { $credits = $user->credits - 1000; $query = mysql_query("UPDATE `users` SET credits = '$credits' WHERE `id` = '$user->id'"); } } } ?> <div style="text-align:left;"> <form action="" method="post" name="feature"> <input type="hidden" name="hdn_abc" value="submit" /> <a href="#" onclick="submitform()">Feature Me!</a> (1000 Credits!) </form> </div> Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 6, 2010 Author Share Posted May 6, 2010 phpchamps - nothing happens with that either.. Just refreshes the page. I didn't even get an alert? PFMaBiSmAd - What would I do from a href, call a php function via an onclick? Quote Link to comment Share on other sites More sharing options...
phpchamps Posted May 6, 2010 Share Posted May 6, 2010 code is working on my machine.. are you sure your browser's javascript is not off???? which browser you are using???????? I would suggest you to clear cache of your browser and then try again..... Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 6, 2010 Author Share Posted May 6, 2010 I cleared the cache and still didn't work... I'm using Firefox 3.6 Javascript is not turned off.. I use it in many accasions on my site. P.S Your signature has a spelling mistake in "phpchamp" Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2010 Share Posted May 6, 2010 I don't know why you are a using a form, using javascript, or even have a title that contains 'form validation' (there's no form data, so there is nothing to validate.) You are just checking if a link has been clicked - <?php if(isset($_GET['submit'])) { if($user->credits < '1000') { echo '<span style="color:#e11919;>Not enough credits!</span>'; } else { $time = time(); $query = mysql_query("INSERT INTO `featured_member` (user_id, views, date) VALUES ('$user->id', '0', '$time')"); if($query) { $credits = $user->credits - 1000; $query = mysql_query("UPDATE `users` SET credits = '$credits' WHERE `id` = '$user->id'"); } } } ?> <div style="text-align:left;"> <a href="?submit">Feature Me!</a> (1000 Credits!) </div> Quote Link to comment Share on other sites More sharing options...
phpchamps Posted May 6, 2010 Share Posted May 6, 2010 hows that possible.. its working like a charm here.. .. u have web developer toolbar installed for firefox??? if you have can you post the error here... because without error its really impossible to find the cause.... Thanks for information abt the spelling mistake:) Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 6, 2010 Author Share Posted May 6, 2010 Oh dang yes. I didn't see that one... Maybe I'm still asleep! Thanks. Quote Link to comment 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.