SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $PHP_SELF and include files

    Hi,

    I am trying to create a contact form that sends a e-mail to a specified e-mail account. Thus far I have been able to send an e-mail through the form. For security reasons and also to filter out rubbish, the data needs to be validated before sending the e-mail.

    After a user submits the a form the data needs to be validated and if filled out correctly an e-mail is send. If not the user needs to stay on the same page with a warning that the data is missing or not correct.

    To accomplish this I want to use the $PHP_SELF action. However, for the layout my site uses templates that are included through an include_once function. At first I want to use an IF / ElSE statement in combination with to inject the template with HEREDOC. However, with HEREDOC I haven't been able to use my include files.


    Could someone offer me general advice how to accomplish this?

  2. #2
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header

    <?php
    //php part

    if(isset($_POST['submit'])
    {
    do form processing


    //on success
    require_once('footer.php');
    exit();

    //you need footer you can include it here...
    //not clean method ...many idea here

    }

    ?>

    show form in plain html
    in value do
    value=<?php if (isset($_POST['value'])) echo $_POST['value']; ?>


    just a baisc algorithm
    hope this helps...
    thanks
    footer.php

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are pretty much discussions on this before in this forum. So please try to search in the forum before you discuss more here. But what I would recommend is:

    - Make a form that is submitted in the page.
    - Check whether the form is posted in the page on top of the page.
    (very top of the page so that you can redirect the browser upon success to another page without header already sent warning)
    - Check if any errors found. If not found then do send email. Otherwise let the process on the same page.

    See the following script:
    PHP Code:
    if($_SERVER['REQEUST_METHOD'] == 'POST'){
        
    $error = array();
        
    $name mysql_real_escape_string($_POST['name']);
        if(empty(
    $name)){
            
    $error['name'] = 'Name is required';
        }
        if(empty(
    $error)){
            
    // do send emails or do whatever you want here
            // redirect to thank you page or some other pages or at least redirect the browser to the same page.
            // so that it wont resubmit the form when refreshed the page.
        
    }
        
    // else it will automatically stay in the same page
    }
    // your form will be here. 
    Please read the comments carefully.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Sorry, I must have been using the wrong keywords for my search. Where can I find an earlier discussion on this topic?

    I am getting the basics, but more information would be helpful.


Tags for this Thread

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
  •