...

View Full Version : Need help with simple form validation



sapecato
10-04-2011, 04:51 PM
I am trying to have the page go to another page after clicking the submit button.

is it possible to add to this function an else statement ?
if form is filled then go to this page




function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus();
return false;
}
return true;
}

Philip M
10-04-2011, 05:15 PM
Submitting the form causes the page to refresh/reload, so you cannot then redirect.

To redirect to a new page after a form submission you must use server-side coding.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

sapecato
10-04-2011, 09:38 PM
Thank you so much for your quick reply.. I al trying to send the _REQUEST fields to my email any sugestions



<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Info Request @ Deluxe Home Improvements";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@deluxehomeimprovements.com";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.ascribble.com" );}
else
{print "We encountered an error sending your mail, please notify webmaster@deluxehomeimprovements.com"; }
}
}
?>







I am trying to send the $_REQUEST fields to my email...

rangana
10-04-2011, 10:51 PM
Seemed to work fine for me. I uploaded the script you sent immitating the request and got the desired result:

http://ray.ph/dev/index.php?sendto=YOUR_EMAIL&Email=TEST_EMAIL&Name=ray&Company=Company_Test&Phone=222&list=list here&Message=this is my message

It might be related to your markup... if so, letting us know about it or a link to that page would help.

sapecato
10-05-2011, 12:26 AM
I m still not getting anything in my inbox.

rangana
10-05-2011, 12:31 AM
Did you modified the values of YOUR_EMAIL and TEST_EMAIL to yours from the link I've given you? I tried it and I did received the email fine.

How about the page where the markup is created? Maybe there's something wrong with the naming you did. Note there are uppercase and the script is case-sensitive.

sapecato
10-05-2011, 12:58 AM
Hello rangana.. how do I change that?

rangana
10-05-2011, 01:03 AM
This is the test case I created on my server:


http://ray.ph/dev/index.php?sendto=YOUR_EMAIL&Email=TEST_EMAIL&Name=ray&Company=Company_Test&Phone=222&list=list%20here&Message=this%20is%20my%20message


You need to change the highlighted with your emails and test it. You will receive a message with all the details that you placed on:


foreach($fields as $a => $b) {
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
}


This will help you confirm that it's not the PHP that's causing trouble but most likely from your HTML markups.

With that said, a link to your page where you have the contact form in action will be of help.

sapecato
10-05-2011, 01:07 AM
<form action="contact.php" method="POST" name="sendto"
value="<?= mail('myemail@mail.com')?>" >
<table border="0" cellspacing="4">
<tr><td><div style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#7ce853; ">Name&ensp;*</div>
<input type="text" size="23" name="Name" value="<?=$Name?>" /></td></tr>
<br />
<tr>
<td><div style="font-family:Arial, Helvetica, sans-serif;font-size:12px; color:#7ce853; ">Property&ensp;Address&ensp;</div>
<input type="text" size="23" name="Address">
</td>
</tr>

<tr>
<td><div style="font-family:Arial, Helvetica, sans-serif;font-size:12px; color:#7ce853; ">Zipcode&ensp;*</div><input type="text" size="12" name="Zip" value="<?=$Zip?>">
</td>
</tr>

<tr>
<td><div style="font-family:Arial, Helvetica, sans-serif;font-size:12px; color:#7ce853; ">Email address&ensp;*</div>
<input type="text" size="23" name="Email" value="<?=$Email?>" />
</td>
</tr>

<tr>
<td><div style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#7ce853; ">Phone&ensp;*</div>
<input type="Phone" size="12" value="<?=$Phone?>" /></textarea>
</td>
</tr>
<tr>
<td height="20">
</td>
</tr>
<tr align="right"><td><input type="submit" value="SUBMIT" class="button" border="no"></td></tr>
</table>
</form>

this is the link to the form

http://deluxehomeimprovements.com/form.php

by the way it did worked when I changed the highlighted areas..

but how do i apply it to the script..

thanks so much

rangana
10-05-2011, 01:18 AM
You were missing fields with names "Company", "list" and "Message". To fix that, just add another fields in your form with those IDs on them.

Also, on your PHP, you had this:


$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email']


I think you need to change $to with the guest's email and $from with your email. Something like:


$to = $_REQUEST['Email'];
$from = admin@deluxehomeimprovements.com;



Hope that keeps you going.

sapecato
10-05-2011, 01:39 AM
You were missing fields with names "Company", "list" and "Message". To fix that, just add another fields in your form with those IDs on them.

Also, on your PHP, you had this:


$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email']


I think you need to change $to with the guest's email and $from with your email. Something like:


$to = $_REQUEST['Email'];
$from = admin@deluxehomeimprovements.com;



Hope that keeps you going.

I did this instead and it worked!!!





$to = 'admin@myemailserver.com';
$from = $_REQUEST['Email'];




Thanks for taking me to the right path!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum