Jump to content

Recommended Posts

Hi. I have a form on a website which originally contained all form text fields and the validation worked fine until I was asked to add a Menu form field to it.

 

Now the validation doesn't work at all and you can submit the form even if no values are entered in to the form.

How do I validate menu form fields?

 

Heres my code for the form with the validation (dreamweaver)

<form action="cgi-bin/sendmail4.php" method="post" enctype="multipart/form-data" name="contact" target="_self" id="contact" onsubmit="MM_validateForm('fname2','','R','sname2','','R','email_from','','RisEmail','telephone2','','RisNum','postcode2','','R',,'Heard-about-us','','R''address2','','R','enquiry2','','R');return document.MM_returnValue">
          <table width="100%" border="0" align="left" cellpadding="2" cellspacing="2">
<tr>
                <td valign="top"><p>First name:
                  <br />
                  <input name="fname2" type="text" class="form" id="fname2" />
                  </p>              </td>
            </tr>
              <tr>
                <td valign="top">Last name:<br />
                    <input name="sname2" type="text" class="form" id="sname2" /></td>
              </tr>
              <tr>
                <td valign="top">Address:<br /><textarea name="address2" cols="45" rows="5" class="form" id="address2"></textarea></td>
              </tr>
              <tr>
                <td valign="top">Email Address:<br />
                    <input name="email_from" type="text" class="form" id="email_from" /></td>
              </tr>
              <tr>
                <td valign="top">Telephone (No spaces)</td>
              </tr>
              <tr>
                <td valign="top"><label>
                  <input name="telephone2" type="text" class="form" id="telephone2" />
                </label></td>
              </tr>
              <tr>
                <td valign="top"><p>Postcode</p>
                <p>
                  <input name="postcode2" type="text" class="form" id="postcode2" />
                </p></td>
              </tr>
              <tr>
                <td valign="top">Where did you hear about us?<br />
                  <select name="Heard-about-us" type="text" class="form" id="Heard-about-us">
                  
                  <option value="Internet Search">Internet Search</option>
                  <option value="Received information in the post">Received information in the post</option>
                  <option value="Yellow Pages or Yell.com">Yellow Pages or Yell.com</option>
                  <option value="Saw a van or tanker">Saw a van or tanker</option>
                  <option value="Existing customer">Existing customer</option>
                  <option value="ICES year book">ICES year book</option>
                  <option value="Municiple year book">Municiple year book</option>
                  <option value="Other">Other</option>
                </select></td>
              </tr>
              <tr>
                <td valign="top"><label>Enquiry<br />
                  <textarea name="enquiry2" cols="45" rows="5" class="form" id="enquiry2"></textarea>
                </label></td>
              </tr>
              <tr>
                <td valign="top"><p>
                    <input name="register2" type="submit" class="form" value="Send" />
                  </p>
                  
                    <p> </p></td>
              </tr>
        </table>
        
        </form>

 

And here is the php form processor

<?php

ini_set('sendmail_from', '[email protected]');
$email_to = "[email protected]";
$fname2 =$_POST['fname2'];
$sname2 =$_POST['sname2'];
$email_from =$_POST['email_from'];
$telephone2 =$_POST['telephone2'];
$heardabout =$_POST['Heard-about-us'];
$postcode2 =$_POST['postcode2'];
$enquiry2 =$_POST['enquiry2'];
$address2 =$_POST['address2'];
$email_subject = "Contact Page";
$headers = 
"From: $email_from .\n";
"Reply-To: $email_from .\n";


$message= "First Name: ". $fname2  . "\nLast Name: " . $sname2 . "\nEmail: " . $email_from . "\nTelephone: " . $telephone2 . "\nHeard About Us: " . $heardabout . "\nPostcode: " . $postcode2 . "\nAddress: " . $address2 . "\nEnquiry: " . $enquiry2;  /* the message will contain the name and the comments */

$sent = mail($email_to, $email_subject, $message, $headers, '-f .$email_from');
if ($sent)
	{
		/*If sent direct customers to thankyou page */
		header( "Location: http://www.whateverurl.com/thankyou.html" ); 
	} else {
		/* If there is an error display an error message */
		echo 'There has been an error sending your comments. Please try later.'; 
	}
?>

 

Thanks guys

Link to comment
https://forums.phpfreaks.com/topic/194049-validating-menu-form-fields/
Share on other sites

The code for the validation is at the top of the first code block and the problem isnt that it doesnt submit because it does. The problem is that the validation is there to make sure that all the fields are campleted before you submit it but currently the form will submit even if you do not fill it in.

The code for the validation is at the top of the first code block and the problem isnt that it doesnt submit because it does. The problem is that the validation is there to make sure that all the fields are campleted before you submit it but currently the form will submit even if you do not fill it in.

 

The call to the function that validates is there, sure, but the function itself is not. It's hard to tell you what the function is doing wrong when we can't see the function. :shrug:

 

I didn't say the form wasn't submitting, I said of course it was! There's nothing to stop it from submitting - or rather, nothing that we can see. ;)

 

[edit]Also, if your validation is done entirely in javascript, realize that anyone can simply disable javascript and submit your form without any validation. Validating on the client side is great to save the user time, but you should NEVER consider client submitted data valid when it gets to the server. All real validation occurs server side, not client side.[/edit]

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.