Link to home
Start Free TrialLog in
Avatar of jonofat
jonofat

asked on

Form won't stop submitting

It appears that this form keeps submitting or something? The form doesn't redirect anywhere after submitting. I must just stay on the same page but it seems like it just keeps going. How do I stop it?
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

do you have an action on the form? if not it will submit back to the same page and then it will not go anywhere.
hi,
maybe you have
<body onload='document.yourform.submit();'>

Open in new window

on the page?
if there is no action then the form submits to the same page. But, still it should not keep on submitting itself again and again unless triggered.

Please show the code that would provide some more insight into the problem.
can we see the page ?? or html source code from your form page and result page
Please post the URL of the page that is giving you trouble.  Please post the script code that is giving you trouble.  Thanks, ~Ray
Avatar of jonofat
jonofat

ASKER

There is an action on the form that I can't remove as I need it. All I did was make it post to another page. Unless anyone can give me a reason why this could be a problem, I am happy to leave it like that and I get the result I want. FYI though, code is..

<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
          <table width="65%" border="0" cellspacing="2" cellpadding="2">
            <tr>
              <td width="9%">&nbsp;</td>
              <td bgcolor="#D71820"><span class="headingtext"><strong>FORGOTTEN PASSWORD
                
                
                    <input name="token" type="hidden" id="token" value="<?php echo md5(mt_rand()); ?>" />
                    <input name="customerid" type="hidden" id="customerid" value="<?php echo $row_Recordset1['customerid']; ?>" />
              </strong></span></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td class="headingtext">If that email address is registered with us, you should receive an email shortly. </td>
              </tr>
          </table>
          <input type="hidden" name="MM_update" value="form1" />
        </form>

Open in new window

Look at "view source" of this page.  My guess is that the $editFormAction variable is undefined and you will see something like this:

<form action="" id="form1" name="form1" method="POST">

If the action= attribute of the form tag is empty the script will GET or POST to its own URL.
ASKER CERTIFIED SOLUTION
Avatar of crazedsanity
crazedsanity
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonofat

ASKER

Sorry for the delay in responding...

I have decided to make it go to another page so it isn't really an issue anymore. The issue is that the form is meant to submit on it's own and then redirect. The form submission is meant to update a record in the database but it doesn't. So, the form appears to be submitting and it redirects, but it isn't actually submitting?

<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
          <table width="65%" border="0" align="center" cellpadding="2" cellspacing="2">
            <tr>
              <td width="9%">&nbsp;</td>
              <td bgcolor="#D71820"><span class="headingtext">FORGOTTEN PASSWORD<strong>
<input name="token" type="hidden" id="token" value="<?php echo md5(mt_rand()); ?>" />
                    <input name="customerid" type="hidden" id="customerid" value="<?php echo $row_Recordset1['customerid']; ?>" />
              </strong></span></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td class="headingtext">If that email address is registered with us, you should receive an email shortly. </td>
              </tr>
          </table>
          <input type="hidden" name="MM_update" value="form1" />
        </form>
        <script>
document.form1.submit();
</script>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jonofat

ASKER

Okay, but if I don't submit a form, how do I update the records in the database then? The purpose of this isn't just to send an email. I need to update a record in the database and send an email.
If I have not recommended this book before, it is my omission.  I apologize and I am glad to recommend it now.  From this question I can tell that you are floundering a little in some of the basics of how web applications work, and this book will really help you get some of the foundation you need.   It is very readable with great examples and has been a part of my professional library since its first edition, several years ago.
http://www.sitepoint.com/books/phpmysql4/

Submitting a form has nothing to do with updating a data base.  You may find these elements of programming together quite often, but they are not intrinsically linked in any way.  Since you have got a variable that identifies a row in the data base like $row_Recordset1['customerid'] you can use this variable in an update query, something like this code snippet (substituting your specific information for anything that starts like my_).

Anyway, this question has been going on for quite some time now.  Earlier I had asked for the URL and the script and since you did not post either of these, except for a little HTML, I will sign off on the question now.  I urge you to buy that book and work through the examples and exercises.  It will not make you a pro, but it will be enjoyable and you will come out of the learning process well ahead.

Best of luck going forward, ~Ray
$c = mysql_real_escape_string($row_Recordset1['customerid']);
$q = "UPDATE my_table SET my_column='$my_value' WHERE my_customerid='$c' LIMIT 1;
$r = mysql_query($q) or die( mysql_error() );
mail ($my_email, $my_subject, $my_message);

Open in new window

Avatar of jonofat

ASKER

Ray, before your response I managed to sort it out. On the same page the user enters their email, when they click submit I have the random key update in the database and an email is sent all on the same page. I just wasn't thinking it through properly. I did take your advice a long time ago and I did purchase that book in pdf format already. I just honestly haven't had time to go through it properly. I am trying to do this and record my new album at the same time. Maybe I can teach you something about sound engineering?? :P