A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Im Lost!

  1. #1
    Junior Member
    Join Date
    Jul 2004
    Location
    UAE
    Posts
    3

    Im Lost!

    ok im trying to do this mail send form in my own way trying not to get any code from outside.. I HAD to copy the
    Code:
    if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/",
    because i need it and i cant really understand it as a php begginer yet..

    I know there are alot of mistakes i know most of them but i do Not know how to fix them..

    Here's the Code.


    PHP Code:
    <?php

    $output 
    "no";
    $check $_POST['output'];
    $message $_POST['message'] ;
    $topic $_POST['topic'];
    $from $_POST['email'];
    $to "[email protected]";

    function 
    checkmail($cm) {
        if (!
    preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/"$from)) {
    echo 
    "<a href='javascript:alert(Invalid email Address);'></a>";
        }
    }

    function 
    checkfield($cf) {
        if (
    $subject == "" || $topic == "" || $from == "" ) {
    echo 
    "<a href='javascript:alert(Please check the missing fields);'></a>";
        }
    }

    if(
    $check == "yes" && $cm true && $cf true  ) {
    mail($to$topic "From: $from . $message");
    echo 
    "<p align=\"center\"><font face=\"Verdana\" color=\"red\">You're mail has been successfully sent.</font></p>";
        }
    ?>

                    <td height="323"><div id="contactus" class="generic">
                      <form action="<?php print $_SERVER['PHP_SELF']?>" method="post">
                        <b>Email</b>: (Required If Your expecting an answer):<br>
                        <input type="hidden" name="output" value="yes">
                        <p><input type="text" name="email" size="20"></p>
                        <b>Title</b>:<br>
                        <p><input type="text" name="topic" size="20"></p>
                        <b>Message</b>:<br>
                        <p>
                        <textarea cols="50" rows="10" name="Message"></textarea>
                        </p>
                        <input type="submit" value="send">
                        <input name="Reset" type="reset" value="reset">
                        </form>
    </div>
    Any advices would be super!
    xXx

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Where is your error and what is it?

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    well, to put in in simple words: you are probably familiar with actionscripts, which is quite similar to php. So if you read through that code, there is
    a) some initialisation (getting data from the form)
    b) the definition of a few functions
    c) an if statement that suggests you had called these functions and assigned the results to some variables.
    Now, please note that - unlike actionscript - globals (variables outside functions) must be named as such: you cannot use $from inside a function.
    There IS a way to return results through a parameter, but explicit return are probably better - they are easier to read.
    Like actionscript, single = sign as part of an if(condition) are rarely ever doing something sensible ....
    Finally, parameter structure for mail() is destination email, subject, message, headers. You can visit php.net and enter "mail" into that search box on the right side to see the manual page.
    Adding these changes, you get somewhere near
    Code:
    <?php
    
    $output = "no";
    $check = $_POST['output'];
    $message = $_POST['message'] ;
    $topic = $_POST['topic'];
    $from = $_POST['email'];
    $to = "[email protected]";
    
    function checkmail($from) {
        if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $from)) {
    echo "<a href='javascript:alert(Invalid email Address);'></a>";
             return false;
        }
        return true;
    }
    
    function checkfield() {
        global $subject, $topic, $from;
        if ($subject == "" || $topic == "" || $from == "" ) {
    echo "<a href='javascript:alert(Please check the missing fields);'></a>";
            return true;
        }
        return false;
    }
    // now actually call these
    $cm = checkmail($from);
    $cf = checkfield();
    
    if($cm == true && $cf == true  ) {
    mail($to, $topic , $message, "From: $from"); 
    ....
    BTW: I have not tried whether this thing would work - I have just looked for obvious problems

    Musicman

  4. #4
    Junior Member
    Join Date
    Jul 2004
    Location
    UAE
    Posts
    3
    thanks for the advices i'll check it out! i was trying to use it as
    PHP Code:
    echo "<a href='javascript:alert(Invalid email Address);'></a>"
    but i think it should go like
    PHP Code:
    <?php
    header
    ("Location: javascript:alert('what');");
    ?>
    which still isnt right :P but its closer to the result i wanted to have
    Last edited by xeofreestyle; 11-08-2009 at 07:08 AM.
    xXx

  5. #5
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    I dont think that this will work (or, if it does, it will not work in somebody else's browser)
    So I would recommend to return a form again but to pre-fill it with the visitor's response.
    A suitable fragment could read
    Code:
    <input type=text name=email value="<?if(isset($_POST['email'])) print $_POST['email'];?>">
    Musicman

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center