Jump to content

this form validation is not doing anything


TeddyKiller

Recommended Posts

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>'; 
?>

Link to comment
Share on other sites

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') {

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>


Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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:)

Link to comment
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.