Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    5
    Thanked 1 Time in 1 Post

    Need help with simple form validation

    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

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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    sapecato (10-04-2011)

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    5
    Thanked 1 Time in 1 Post
    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...

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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=Y... 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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    sapecato (10-04-2011)

  • #5
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    5
    Thanked 1 Time in 1 Post
    I m still not getting anything in my inbox.

  • #6
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    sapecato (10-04-2011)

  • #7
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    5
    Thanked 1 Time in 1 Post
    Hello rangana.. how do I change that?

  • #8
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    This is the test case I created on my server:
    Code:
    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:
    PHP Code:
    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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    sapecato (10-05-2011)

  • #9
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    5
    Thanked 1 Time in 1 Post
    Code:
    <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
    Last edited by sapecato; 10-05-2011 at 12:13 AM.

  • #10
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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:
    PHP Code:
    $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:
    PHP Code:
    $to $_REQUEST['Email'];
    $from admin@deluxehomeimprovements.com

    Hope that keeps you going.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    sapecato (10-05-2011)

  • #11
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    7
    Thanks
    5
    Thanked 1 Time in 1 Post

    Smile

    Quote Originally Posted by rangana View Post
    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:
    PHP Code:
    $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:
    PHP Code:
    $to $_REQUEST['Email'];
    $from admin@deluxehomeimprovements.com

    Hope that keeps you going.
    I did this instead and it worked!!!


    PHP Code:

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

    Thanks for taking me to the right path!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •