Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member Tyler Smith's Avatar
    Join Date
    Oct 2011
    Posts
    115
    Member #
    29767
    Liked
    7 times
    Hello all,

    I want to implement this whole e-mail box submission script into PHP, equipped for anti-hijacking, writing the user's e-mail to mySQL database, sending notification e-mail to me of the user joining e-mail list, send welcome e-mail to user, among other little tasks for my pages at worldreviewgroup.com. You'll see below my draft is quite unfinished, and I'm unclear on some aspects.

    Code:
    <?php
          /*This is the scripting section for the e-mail collection box.*/
        $email = " ";
        
        function showWindowAndValidate()
        {
            echo'<div id="activeemailbox"><input type="checkbox" value="Yes\, I would like to join the mailing list."><p>Enter the characters you see below.</p></div>' . generateRandom() . ;    
        }
        
        if (isset($_POST["go"]){
            $email = $_POST["go"];
            if (isItAValidEmail($email))
                //call a function to write the user to database
        } else {
            invalidEntry();
            }
        
        /*test the e-mail address submission for valid entry */
        function isItAValidEmail($email)
        {
            if (preg_match($email, '@') {
                $websiteExtensions = array String (
                '.com', '.net', '.org', '.biz', '.coop', '.info', '.jobs', '.name', '.mobi', '.post', '.tel', '.edu', '.asi', '.cat' );
                for ($i = 0; $i <= count($websiteExtensions); i++)
                {
                    preg_match(/* see if it matches any of the website extensions in $websiteExtensions*/)
                }
            } else (
                invalidEntry();
        }
        
        function invalidEntry()
        {
            echo'<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" onclick="goBack()"></div>';
        }
        
        function generateRandom()
        {
        
        }
        
        function goBack()
        {
            /* go back to the last screen, remove echoed html, whatever */
        }
        //end e-mail box scripting section
    ?>
    I want to know how to go back to the original page or remove HTML inserted with the echo function.
    I don't know how to access the index location (i) in that for loop for my array, $websiteExtensions.

    There is also a short clip of JavaScript, that I want to convert into PHP. This small snippet just takes the "your e-mail" away as the value when the user activates the input field.
    Code:
    function input_focus(obj){
        if ( obj.value == obj.defaultValue ){
            obj.value = ""
        }
    }
    
    function input_reset(obj){
        obj.value = obj.defaultValue;
    }
    Thanks for your help.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    Typically, with PHP, you have a 'return' at the end of your functions.

    As with many scripts, you don't echo things from the functions, but merely return back
    a value(s) that are echoed or displayed or processed.

    $celsius=23;
    echo "The temperature is: ".convert($celsius)." degrees F";

    function convert($value){
    $temp=(9/5)*($value+32);
    return $temp;
    }

    So I think you're looking for the part about 'return'.
    If you need to return several things, you return an array.
    Technically, you can echo (or print) things within the function,
    but in most cases you'll see the functions returning values.
    I see you know javascripting very well but are learning PHP.

    You'll see a lot of similarities, but also differences. You might
    find that Google has quicker answers to your PHP questions
    than using this forum. Also, you can get instant examples
    by searching on Google.

    The part about values in text boxes? PHP can't take the values
    'instantly' like javascripting. The form needs to be submitted
    and the values taken as $_POST ( or $_GET ). One thing you'll
    discover is that javascripting can be used with PHP to do seamless
    things without page refreshes ... that's what AJAX is. If you learn
    PHP, you'll be really good at AJAX (and JQuery with PHP) ... as you
    already know javascripting. Find many AJAX examples using Google.

    Finally, if you put the word PHP first and then what you're looking for,
    you'll get right to the point of your question .... example, to see how
    PHP redirects user to another page/script:
    http://www.google.com/search?q=php redirect&btnG=Search

    To see how you can have PHP read values from your URL, enter this in a Google Search:
    php get variable from url
    Tyler Smith likes this.


  4. #3
    Member
    Join Date
    Nov 2012
    Location
    Tampa. FL
    Posts
    59
    Member #
    33844
    Liked
    21 times
    The function you are looking for to go back to the last screen is called header();
    http://php.net/manual/en/function.header.php
    Tyler Smith likes this.
    Freelance Web Developer


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:34 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com