Advanced Search

Results 1 to 4 of 4

Thread: PHP simplified code.

  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile PHP simplified code.

    Greeting to all. I have persistant unsolved problem. In my website I have a form that works fine:
    Code:
    <form method="POST" name="contactform" action="http://blablabla.com/contact.php"> 
    <input type="text" size="18" maxlength="45">
    <textarea name="message" rows="4" cols="25" size="18">
    </textarea>
    <p>
    <input type="submit" value="Send" name="submit">
    <input type="reset" value="Clear" name="submit">
    </p>
    </form>
    In my .php I have this which works fine:
    PHP Code:
    <?php
    $myemail 
    'blabla@blabla.com';
    error_reporting(0);
    $message $_POST['message']; 
    $email trim($_POST['email']);
    $Ok ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"$email);
    if (
    $Ok) {
        
    $to $myemail
        
    $email_subject "Contact Form blblblbaa.com.";
        
    $email_body "Email: $email \n Message: $message"
        
        
    $headers "From: $email\n"
        
    $headers .= "Reply-To: $myemail";
        
    mail($to,$email_subject,$email_body,$headers);

        if(!
    ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
        {
        
    ?>
    [B]<script language = 'javascript'>
        alert('Thank you.');
        history.go(-1);
        </script>[/B]
    <?
        
    exit();
        }


    else {
        if(!
    ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$UNameFrm))
        {
        
    ?>
    [B]<script language = 'javascript'>
        alert('Please provide a valid email.');
        history.go(-1);
        </script>[/B]
    <?
        
    exit();
        }
    }

    ?>
    Can you please help me get rid of the pop up windows created by the alerts in the .php? It would be much better if everything happens on the page.

    Thank you for your time and help.
    Last edited by Beverleyh; 07-07-2013 at 01:13 PM. Reason: formatting

  2. #2
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Solved it!

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,621
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    glad you solved it. As a side note, the ereg functions are deprecated:
    Quote Originally Posted by php.net/ereg
    Warning
    This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
    Additionally, your regex will reject some valid email addresses (including several of mine, in fact). A better way to validate an email address is by using filter_var:
    PHP Code:
    <?php
    $Ok 
    filter_var$_POST['email'],FILTER_VALIDATE_EMAIL );

    // or, if you want to enforce a tld in the domain part (probable):
    $Ok filter_var$_POST['email'],FILTER_VALIDATE_EMAIL ) && preg_match'#\.[\w]{2,}$#',$_POST['email'] );
    and finally...

    If your question has been answered, please mark your thread "resolved":
    • On your original post (post #1), click [edit], then click [go advanced].
    • In the "thread prefix" box, select "Resolved".
    • Click [save changes].

    If you have not already done so, you should also consider sharing the solution to your problem.
    This may be beneficial to others who encounter similar issues in the future.


    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  4. #4
    Join Date
    Jul 2012
    Posts
    197
    Thanks
    55
    Thanked 3 Times in 3 Posts

    Default

    Can you please help me get rid of the pop up windows created by the alerts in the .php? It would be much better if everything happens on the page.
    I would like to recommend jQuery Ajax for displaying validation messages in same page itself, it's clean and rigid
    You will know the truth, and the truth will set you free (John 8:32)(The truth is about the only begotten son of GOD.....When you feel you are alone for facing your problems, God will never leave you by your own You are important for God

Similar Threads

  1. Modal Script Simplified
    By ElenaT in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-21-2009, 02:08 AM
  2. Replies: 2
    Last Post: 10-27-2008, 05:16 AM
  3. Replies: 0
    Last Post: 10-02-2008, 07:51 PM
  4. [DHTML] ActiveX Simplified
    By magicgavin in forum Submit a DHTML or CSS code
    Replies: 35
    Last Post: 07-18-2007, 11:09 PM
  5. Simplified Ajax Loaded Content w/scripts requiring onload events
    By jscheuer1 in forum Coding tips & tutorials threads
    Replies: 0
    Last Post: 02-11-2007, 04:54 PM

Bookmarks

Posting Permissions

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