Hello,
I am new to php and cannot see why this page is not working. I have spent days on trying to find the fault but can't. The problem is that sometimes the form works correctly and sometimes it doesn't. On the receiving page I use _POST to display the contents from the registration form page. Sometimes all of the reults are returned:

I have added Javascript to the code (which I have not added to the forum) so the form cannot be submitted without all the fields being completed. I would be very grateful if someone can see what could be wrong. Thank you for your time.

To find the problem you may want to remove the Javascript then try to reproduce the problem. If it doesn't happen with the Javascript removed, you know it's got to be something about the Javascript.

mrcurtains

12-08-2008, 05:25 PM

Thank you. I have removed the javascript and I can't see a difference. I have tested the page hundreds of times and it works everytime for me if the Javascript has been removed or not. However, if fails to receive information 1 in 20-30 customers.

Here is the Javascript and I can't see reason why it would stop posted values from being sent to the receiving page.

<!--
function fieldCheck(){

if(document.registrations.reg1_title.value=="")
{
alert("Title field should not be empty.");
document.registrations.reg1_title.focus();
return false;
}
if(document.registrations.reg1_surname.value=="")
{
alert("Surname field should not be empty.");
document.registrations.reg1_surname.focus();
return false;
}

if(document.registrations.reg1_forename.value=="")
{
alert("First Name field should not be empty.");
document.registrations.reg1_forename.focus();
return false;
}

if(document.registrations.reg1_email.value=="")
{
alert("Email Address field should not be empty.");
document.registrations.reg1_email.focus();
return false;
}

Your form processing code is not checking in any way that the form was submitted, so if the symptom is an email with array ( ) in it, then it is because someone (or a search engine) requested the page directly without submitting the form.

You need to give your submit button a name="..." parameter and then check in the form processing code that the $_POST variable by that name is set.

mrcurtains

12-09-2008, 10:37 AM

Excellent, well noticed. I didn't even think about that. I have added the check and will hopefully see if this has solved the problem. Thank you for your help :thumbsup:.

mrcurtains

12-10-2008, 08:56 AM

:confused: It didn't work. I used the following code around the form processing:

if(isset($_POST['btnSubmit'])) {

}

But empty fields are still returned. Is the above code correct? But it works some times and not others it is difficult to find out why is it not working. Thanks.

abduraooft

12-10-2008, 09:32 AM

Where is your submit button having an attribute name="btnSubmit"?

mrcurtains

12-10-2008, 10:58 AM

I have edited the original post and have added the name to the button, thanks.

CFMaBiSmAd

12-10-2008, 01:17 PM

It would take seeing your form processing code with the code to check $_POST['btnSubmit']

I copy and pasted your form at http://validator.w3.org and there are some closing td/tr/table tags that it found a problem with. This could cause different browsers to treat the form differently and perhaps not submit the data. Having error free markup would eliminate this as a possible reason.

Do you believe real visitors are entering data and it does not get submitted or could you have a spam bot script submitting data to or probing your form processing code? Why are you adding the javascript validation? If it is to prevent spam, then it won't because spam bot scripts submit data directly to your form processing page and could care less about anything you do to your form. Even if you have javascript validation in the form as an aid to your real visitors entering data, you must validate the data after it has been received on the server in your form processing code. This would eliminate empty emails, prevent spam, and help the visitors in the cases where they have javascript disabled.

CFMaBiSmAd

12-10-2008, 01:43 PM

The code you posted in the first post, is that actually two separate files and just got posted in one set of code tags or is all of that in one file?

mrcurtains

12-10-2008, 02:39 PM

Hi,

I had posted the two pages together in the script tag. I have now separated them. I believe the user are submitting the forms, though I can't be completely sure. The Javascript is only to stop users submitting the form before all fields are complete. Though there seems to be a lot of registrations from people who have Javascript turned off.

The </td> error was my lack of skill with cutting and pasting. My original form contains about 100 fields so I have drastically shortened the fields to make it easier to read. I have checked the fields that I have removed and there is nothing incorrect about them.

CFMaBiSmAd

12-10-2008, 02:46 PM

How about this part -

It would take seeing your form processing code with the code to check $_POST['btnSubmit']

mrcurtains

12-10-2008, 03:11 PM

The form processing code just takes the fields passed to the page, concatinates a string then saves them to a session to use later. As the information doesn't get this far I have not included this so that the code is easier to read.

<?php
// If the previous page has not been submitted do not check the form posted
if(isset($_POST['btnSubmit'])) {
$sqlColumn = "reg1_title, reg1_surname, reg1_forename, reg1_email";

The majority of the time I get an email with all the fields filled in. However, a few times a day I get blank emails sent to me.

CFMaBiSmAd

12-10-2008, 03:39 PM

I recommend using error_log() to create a log file of all the available information each time your form processing code is requested. You should do this for any real application so that you have a record of activity in your application. Use any or all of the following -

<?php
// basic form and form processing code with logging of both good and bad submission data -

// display the form if it has not been submitted or there are form validation errors
If(!$submitted || !empty($form_error)) {
// check for and display any form validation errors
if(!empty($form_error)) {
echo "Please correct these errors -<br />";
foreach($form_error as $error) {
echo "$error<br />";
}
}