Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 28

Discussione: Modificare un form php

  1. #1

    Modificare un form php

    Allora ragazzi in questo form quando mi arriva l'email con la scritta
    element_1_1:
    element_1_2:
    element_2:
    element_3:
    element_4:
    element_5_1:
    element_5_2:
    element_5_3:
    element_5_4:
    element_5_5:
    element_5_6:
    element_6:
    element_7:
    element_8:
    element_9:
    form_id: 572576
    submit: Invio

    il codice php in questione è


    codice:
    <?php
    //This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the <code>name</code> attribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you've added it to the script).
    
    if (empty($_POST)) {
    	print "
    
    No data was submitted.</p>";
    	print "</body></html>";
    	exit();
    }
    
    //Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
    function clear_user_input($value) {
    	if (get_magic_quotes_gpc()) $value=stripslashes($value);
    	$value= str_replace( "\n", '', trim($value));
    	$value= str_replace( "\r", '', $value);
    	return $value;
    	}
    
    
    if ($_POST['comments'] == 'da cambiare ') $_POST['da cambiare'] = '';	
    
    //Create body of message by cleaning each field and then appending each name and value to it
    
    $body ="queste sono le informazioni di registrazione utente\n";
    
    foreach ($_POST as $key => $value) {
    	$key = clear_user_input($key);
    	$value = clear_user_input($value);
    	if ($key=='extras') {
    		
    	if (is_array($_POST['extras']) ){
    		$body .= "$key: ";
    		$counter =1;
    		foreach ($_POST['extras'] as $value) {
    				//Add comma and space until last element
    				if (sizeof($_POST['extras']) == $counter) {
    					$body .= "$value\n";
    					break;}
    				else {
    					$body .= "$value, ";
    					$counter += 1;
    					}
    				}
    		} else {
    		$body .= "$key: $value\n";
    		}
    	} else {
    
    	$body .= "$key: $value\n";
    	}
    }
    
    extract($_POST);
    //removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
    $email = clear_user_input($email);
    $name = clear_user_input($name);
    
    
    
    
    //Creates intelligible subject line that also shows me where it came from
    $subject = 'OGGETTO DELLA MAIL';
    
    //Sends mail to me, with elements created above
    mail ('xxx@iol.it', $subject, $body, $from);
    
    
    ?>
    posso aggiungere piu email? posso cambiare l'etichette di arrivo email? ,

  2. #2
    codice:
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Untitled Form</title>
    <link rel="stylesheet" type="text/css" href="view.css" media="all">
    <script type="text/javascript" src="view.js"></script>
    
    </head>
    <body id="main_body" >
    	<div id="form_container">
    	
    		<form id="form_572576" class="appnitro"  method="post" action="iscrizione.php">
    					<div class="form_description">
    			<h2></h2>
    			
    
    Compila il modulo sottostante, e sarai contattato al più presto</p>
    		</div>						
    			<ul >
    			
    					<li id="li_1" >
    		<label class="description" for="element_1">Nome e Cognome </label>
    		<span>
    			<input id="element_1_1" name= "element_1_1" class="element text" maxlength="255" size="8" value=""/>
    			<label>Nome</label>
    		</span>
    		<span>
    			<input id="element_1_2" name= "element_1_2" class="element text" maxlength="255" size="14" value=""/>
    			<label>Cognome</label>
    		</span> 
    				<li id="li_2" >
    		<label class="description" for="element_2">Codice Fiscale </label>
    		<div>
    			<input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value=""/> 
    		</div> 
    				<li id="li_3" >
    		<label class="description" for="element_3">P.Iva </label>
    		<div>
    			<input id="element_3" name="element_3" class="element text small" type="text" maxlength="255" value=""/> 
    		</div> 
    				<li id="li_4" >
    		<label class="description" for="element_4">Azienda </label>
    		<div>
    			<input id="element_4" name="element_4" class="element text medium" type="text" maxlength="255" value=""/> 
    		</div> 
    				<li id="li_5" >
    		<label class="description" for="element_5">Recapito destinatario </label>
    		
    		<div>
    			<input id="element_5_1" name="element_5_1" class="element text large" value="" type="text">
    			<label for="element_5_1">Via</label>
    		</div>
    	
    		<div>
    			<input id="element_5_2" name="element_5_2" class="element text large" value="" type="text">
    			<label for="element_5_2"></label>
    		</div>
    	
    		<div class="left">
    			<input id="element_5_3" name="element_5_3" class="element text medium" value="" type="text">
    			<label for="element_5_3">Città </label>
    		</div>
    	
    		<div class="right">
    			<input id="element_5_4" name="element_5_4" class="element text medium" value="" type="text">
    			<label for="element_5_4">Provincia</label>
    		</div>
    	
    		<div class="left">
    			<input id="element_5_5" name="element_5_5" class="element text medium" maxlength="15" value="" type="text">
    			<label for="element_5_5">Postale / C.A.P </label>
    		</div>
    	
    		<div class="right">
    			<select class="element select medium" id="element_5_6" name="element_5_6"> 
    			<option value="" selected="selected"></option>
    <option value="Afghanistan" >Afghanistan</option>
    <option value="Albania" >Albania</option>
    <option value="Algeria" >Algeria</option>
    <option value="Belarus" >Belarus</option>
    .......................................
    .....
    ..
    			</select>
    		<label for="element_5_6">Nazione</label>
    	</div> 
    				<li id="li_6" >
    		<label class="description" for="element_6">Tell </label>
    		<div>
    			<input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
    		</div> 
    				<li id="li_7" >
    		<label class="description" for="element_7">Cell </label>
    		<div>
    			<input id="element_7" name="element_7" class="element text medium" type="text" maxlength="255" value=""/> 
    		</div> 
    				<li id="li_8" >
    		<label class="description" for="element_8">Email </label>
    		<div>
    			<input id="element_8" name="element_8" class="element text medium" type="text" maxlength="255" value=""/> 
    		</div> 
    				<li id="li_9" >
    		<label class="description" for="element_9">Note </label>
    		<div>
    			<textarea id="element_9" name="element_9" class="element textarea medium"></textarea> 
    		</div> 
    		
    			
    					<li class="buttons">
    			    <input type="hidden" name="form_id" value="572576" />
    			    
    				<input id="saveForm" class="button_text" type="submit" name="submit" value="Invio" />
    		
    			[/list]
    		</form>	
    		<div id="footer">
    		
    		</div>
    	</div>
    	[img]bottom.png[/img]
    	</body>
    </html>

  3. #3
    grazie

  4. #4
    vorrei mettere anche delle restrizioni tipo campo obbligatorio

  5. #5
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746

    Re: Modificare un form php

    Originariamente inviato da adempius
    posso aggiungere piu email? posso cambiare l'etichette di arrivo email? ,
    in che senso "posso aggiungere più email"? vuoi inviarla a più indirizzi?

    cos'è l'etichetta di arrivo? forse la conferma di ricezione?

    quando posti del codice php non usare i tag CODE /CODE, bensì quelli PHP /PHP così è più leggibile

    per i campi obbligatori ti consiglio di farlo in due modi, il primo lato client con javascript e successivamente lato server, tipo se vuoi che sia inserito obbligatoriamente il nome farai un controllo tipo

    Codice PHP:
    if ( empty($_POST['element_1_1']) ) echo 'Inserire il nome' 
    Naturalmente se gli obblighi non sono soddisfatti oltre che mandare un messaggio devi anche interrompere lo script di invio.
    Bello ed anche più sofisticato è anche rimandare al modulo di inserimento gli errori rilevati ed evidenziali nelle relative caselle con qualche scritta rossa.

    Ma perchè usi questa nomenclatura delle variabili "element_1_1"...?
    non è più pratico chiamarle con il loro nome?
    Errare humanum est, perseverare ovest

  6. #6
    si a piu indirizzi ,
    il codice php per l'invio che sto usando è questo . ::

    Codice PHP:
    <?php
    //This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the <code>name</code> attribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you've added it to the script).

    if (empty($_POST)) {
        print 
    "

    No data was submitted.</p>"
    ;
        print 
    "</body></html>";
        exit();
    }

    //Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
    function clear_user_input($value) {
        if (
    get_magic_quotes_gpc()) $value=stripslashes($value);
        
    $valuestr_replace"\n"''trim($value));
        
    $valuestr_replace"\r"''$value);
        return 
    $value;
        }


    if (
    $_POST['comments'] == 'da cambiare '$_POST['da cambiare'] = '';    

    //Create body of message by cleaning each field and then appending each name and value to it

    $body ="queste sono le informazioni di registrazione utente\n";

    foreach (
    $_POST as $key => $value) {
        
    $key clear_user_input($key);
        
    $value clear_user_input($value);
        if (
    $key=='extras') {
            
        if (
    is_array($_POST['extras']) ){
            
    $body .= "$key: ";
            
    $counter =1;
            foreach (
    $_POST['extras'] as $value) {
                    
    //Add comma and space until last element
                    
    if (sizeof($_POST['extras']) == $counter) {
                        
    $body .= "$value\n";
                        break;}
                    else {
                        
    $body .= "$value, ";
                        
    $counter += 1;
                        }
                    }
            } else {
            
    $body .= "$key$value\n";
            }
        } else {

        
    $body .= "$key$value\n";
        }
    }

    extract($_POST);
    //removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
    $email clear_user_input($email);
    $name clear_user_input($name);




    //Creates intelligible subject line that also shows me where it came from
    $subject 'OGGETTO DELLA MAIL';

    //Sends mail to me, with elements created above
    mail ('prova@prova.it'$subject$body$from);


    ?>

  7. #7
    si è capito che sono ignorante in materia ma ciò nonostante grazie ai forum sto andando avanti,
    praticamente ho anche il problema che quando uno compila il form, mi arriva un email del form compilato con scritte
    element_1_1:
    element_1_2:
    element_2:
    element_3:
    element_4:
    element_5_1:
    element_5_2:
    element_5_3:
    element_5_4:
    element_5_5:
    element_5_6:
    element_6:
    element_7:
    element_8:
    element_9:

    invece di nome e cognome citta...ecc.

  8. #8
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    Originariamente inviato da adempius
    si a piu indirizzi
    Nel tuo esempio usi questo codice
    Codice PHP:
    //Sends mail to me, with elements created above
    mail ('prova@prova.it'$subject$body$from); 
    L'indirizzo email del destinatario è "prova@preova.it"

    Per inviare l'email a più destinatari dovrai inserire i loro indirizzi nello stesso posto dividendoli tra di loro con la virgola

    Codice PHP:
    mail ('prova@prova.it,prova2@prova.it,prova3@prova.it'$subject$body$from); 
    In rapporto a come gestisci gli indirizzi dei destinatari potrebbe essere conveniente metterli in una variabile ed usarla nella funzione email().

    Codice PHP:
    $indirizzi_destinatari = ('prova@prova.it,prova2@prova.it,prova3@prova.it' ;

    mail ($indirizzi_destinatari$subject$body$from); 
    Errare humanum est, perseverare ovest

  9. #9
    Utente di HTML.it L'avatar di carlo2002
    Registrato dal
    Jun 2002
    Messaggi
    2,746
    Originariamente inviato da adempius
    si è capito che sono ignorante in materia ma ciò nonostante grazie ai forum sto andando avanti,
    praticamente ho anche il problema che quando uno compila il form, mi arriva un email del form compilato con scritte
    element_1_1:
    element_1_2:
    element_2:
    .......

    invece di nome e cognome citta...ecc.
    Non preoccuparti, nessuno nasce imparato, basta poi impegnarsi con passione.

    Ti arrivano quegli "element_" perchè nello script del modulo sono usati come "name" degli "input".

    codice:
    <input id="element_1_1" name= "element_1_1" class="element text" maxlength="255" size="8" value=""/>
    <label>Nome</label>
    
    <input id="element_1_2" name= "element_1_2" class="element text" maxlength="255" size="14" value=""/>
    <label>Cognome</label>
    Non devi fare altro che cambiarli tu stesso

    codice:
    <input id="element_1_1" name= "nome" class="element text" maxlength="255" size="8" value=""/>
    <label>Nome</label>
    
    <input id="element_1_2" name= "cognome" class="element text" maxlength="255" size="14" value=""/>
    <label>Cognome</label>
    ... e così per tutti gli altri
    Errare humanum est, perseverare ovest

  10. #10
    per ora grazie, piu tardi verifico

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.