Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    form richiamato da altra pagina

    ciao a tutti
    ho un form email jquery/php che funziona perfettamente se apro la pagina contact.php direttamente dal browser;

    il tutto con questo codice
    Codice PHP:
    <?php
    //If the form is submitted
    if(isset($_POST['submit'])) {

        
    //Check to make sure that the name field is not empty
        
    if(trim($_POST['contactname']) == '') {
            
    $hasError true;
        } else {
            
    $name trim($_POST['contactname']);
        }

        
    //Check to make sure that the subject field is not empty
        
    if(trim($_POST['subject']) == '') {
            
    $hasError true;
        } else {
            
    $subject trim($_POST['subject']);
        }

        
    //Check to make sure sure that a valid email address is submitted
        
    if(trim($_POST['email']) == '')  {
            
    $hasError true;
        } else if (!
    eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$"trim($_POST['email']))) {
            
    $hasError true;
        } else {
            
    $email trim($_POST['email']);
        }

        
    //Check to make sure comments were entered
        
    if(trim($_POST['message']) == '') {
            
    $hasError true;
        } else {
            if(
    function_exists('stripslashes')) {
                
    $comments stripslashes(trim($_POST['message']));
            } else {
                
    $comments trim($_POST['message']);
            }
        }

        
    //If there is no error, send the email
        
    if(!isset($hasError)) {
            
    $emailTo 'youremail@yoursite.com'//Put your own email address here
            
    $body "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
            
    $headers 'From: My Site <'.$emailTo.'>' "\r\n" 'Reply-To: ' $email;

            
    mail($emailTo$subject$body$headers);
            
    $emailSent true;
        }
    }
    ?>

    <!DOCTYPE html><html lang="en">
    <html><head>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="styles/style01.css" media="screen"/>>
    <script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="script/jquery.validate.pack.js" ></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("#contactform").validate();
    });
    </script>
    </script>
    </head>
    <body>
    <div id="container">
        
            <div id="center">
                <?php
                    
    include "top.php";
                    
    ?>
                <div id="main"> 
    <div id="contact-wrapper">

        <?php if(isset($hasError)) { //If errors are found ?>
            <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p>
        <?php ?>

        <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
            

    [b]Email Successfully Sent![/b]</p>
            

    Thank you [b]<?php echo $name;?>[/b] for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p>
        <?php ?>

        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
            <div>
                <label for="name">[b]Name:[/b]</label>
                <input type="text" size="50" name="contactname" id="contactname" value="" class="required" />
            </div>

            <div>
                <label for="email">[b]Email:[/b]</label>
                <input type="text" size="50" name="email" id="email" value="" class="required email" />
            </div>

            <div>
                <label for="subject">[b]Subject:[/b]</label>
                <input type="text" size="50" name="subject" id="subject" value="" class="required" />
            </div>

            <div>
                <label for="message">[b]Message:[/b]</label>
                <textarea rows="5" cols="50" name="message" id="message" class="required"></textarea>
            </div>
            <input type="submit" value="Send Message" name="submit" />
        </form>
        </div>
         </div>
                
            </div>
            
            <?php
                
    include "right.php";
                
    ?>
                
                <?php
                
    include "footer.php";
                
    ?>
            
        </div>
    </div>
    </div>
    </body>
    </html>
    se invece la pagina la richiamo dall'index con questo metodo:
    http:/.../index.php?sez=contact
    al momento dell'invio mi rimanda all'index
    di sicuro ho capito che il problema è qui perchè la pagina con il form richiamato senza questa funzione funziona solo che a me servirebbe così

    grazie a tutti
    ciao!

  2. #2
    perchè l'action del form è sbagliato
    tu hai:
    Codice PHP:
    action="<?php echo $_SERVER['PHP_SELF']; ?>"
    dovresti sostiurlo con:

    Codice PHP:
    action="" 
    in modo che rinvia nella stessa pagina oppure

    Codice PHP:
    action="<?php echo $_SERVER['REQUEST_URI']; ?>"

  3. #3

    ti ringrazio davvero tanto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.