Foros del Web » Programando para Internet » PHP »

Ayuda con formulario

Estas en el tema de Ayuda con formulario en el foro de PHP en Foros del Web. Hola a todos, soy nuevo en este foro y también en la programación. Me gusta e interesa mucho PHP y en realidad todos los idiomas ...
  #1 (permalink)  
Antiguo 03/12/2009, 06:06
 
Fecha de Ingreso: diciembre-2009
Mensajes: 3
Antigüedad: 14 años, 4 meses
Puntos: 0
Ayuda con formulario

Hola a todos,

soy nuevo en este foro y también en la programación. Me gusta e interesa mucho PHP y en realidad todos los idiomas que nos permite la informática.

Les cuento que estoy haciendo un formulario para hacer pedidos, bastante simple, pero tengo dos grandes problemas (me imagino que para vosotros serán ínfimos), aquí van:

1.- No sé cómo validar mi formulario, es decir, si alguien no llena los campos (nombre, apellido, etc) se debería ver una alerta que me indique que debo llenar los campos dejados en blanco antes de validarlo y enviarlo a la base de datos.

2.- En el caso que la persona llene correctamente el formulario y haga su pedido. Cómo hacer para que el pedido hecho le llegue a quién lo pidió y a la vez a mi mismo a través de un mail, detallando en el mail el producto comprado, su valor neto, el impuesto y el total?

Les adjunto los archivos que he creado, espero me puedan ayudar. Muchas gracias!

Código PHP:
 formulario con los productos ya sumados en documento anterior
<form action="bestellen.php" method="post">

<?php

$_POST
['tc1k'];
$_POST['tc3k'];
$_POST['tc5k'];
$_POST['bio1f'];
$_POST['sjf'];
$_POST['tvf'];
$_POST['gesamtbetrag'];

$preis1 =   $_POST['tc1k']*9.70;
$preis2 =   $_POST['tc3k']*21.70;
$preis3 =   $_POST['tc5k']*35.70;
$preis4 =   $_POST['bio1f']*13.30;
$preis5 =   $_POST['sjf']*11.30;
$preis6 =   $_POST['tvf']*10.10;

$gesamt $preis1 $preis2 $preis3 $preis4 $preis5 $preis6;

$versandkostenpauschale $gesamt 6.9;

$gesamtbetrag $gesamt 6.9;

$preis1 number_format($preis12"," ".");
$preis2 number_format($preis22"," ".");
$preis3 number_format($preis32"," ".");
$preis4 number_format($preis42"," ".");
$preis5 number_format($preis52"," ".");
$preis6 number_format($preis62"," ".");

$versandkostenpauschale number_format($versandkostenpauschale2"," ".");
$gesamt number_format($gesamt2"," ".");
$gesamtbetrag number_format($gesamtbetrag2"," ".");


echo 
" <table  align='center'bgcolor='#FFFFCC'width='720' border='0' cellspacing='2' cellpadding='2'>
    <tr height='50'>
      <td class='text'>producto 1</td>
      <th width='100'><strong>$preis1 €</strong></th>
      <input type='hidden' name='tc1k' value='"
.$_POST['tc1k']."' />
      </tr>
      <hr align='center' width='720' size='7' color='#FF6600' />
      
    <tr height='50'>
      <td class='text'>producto 2</td>
      <th><strong>$preis2 €</strong></th>
      <input type='hidden' name='tc3k' value='"
.$_POST['tc3k']."' />
      </tr>

     <tr height='50'>
      <td class='text'>producto 3</td>
      <th><strong>$preis3 €</strong></th>
      <input type='hidden' name='tc5k' value='"
.$_POST['tc5k']."' />
      </tr>
      
     <tr height='50'>
      <td class='text'>producto 4</td>
      <th><strong>$preis4 €</strong></th>
      <input type='hidden' name='bio1f' value='"
.$_POST['bio1f']."' />
      </tr>
      
     <tr height='50'>
      <td class='text'>producto 5</td>
      <th><strong>$preis5 €</strong></th>
      <input type='hidden' name='sjf' value='"
.$_POST['sjf']."' />
      </tr>
      
     <tr height='50'>
      <td class='text'>producto 6</td>
      <th><strong>$preis6 €</strong></th>
      <input type='hidden' name='tvf' value='"
.$_POST['tvf']."' />
      </tr>
      
      <tr height='50'>
      <td><strong>Gesamtwarenwert </strong></td>
      <th><strong>$gesamt €</strong></th>
    </tr>
    
    <tr height='50'>
      <td>Versandkosten (6,90€)</td>
      <th><strong>$versandkostenpauschale €</strong></th>
    </tr>
    
    <tr height='50'>
      <td> <strong>Gesamtbetrag</strong></td>
      <th><strong>$gesamtbetrag €</strong></th>
      <input type='hidden' name='gesamtbetrag' value='"
.$_POST['gesamtbetrag']."' />
    </tr>
      </table>"
;

 
   echo 
" <table align='center'bgcolor='#8DCB41'width='720' border='0' cellspacing='2' cellpadding='2'>
   <tr>
   <td>
   <strong>Bitte überweisen Sie den Betrag in Höhe von</strong> " 
"<strong>" $gesamtbetrag "</strong>" "<strong>€</strong><br /><br />
   Konto Inhaberin: <strong> nombre</strong><br /><br />
   Konto Nr. <strong>1003333</strong><br /><br /> 
   BLZ 3342233<br /><br /> 
   banco x<br /><br />
   Verwendungszweck: Bitte Ihre Rechnungsnummer angeben.<br /><br />
   <strong>Vielen Dank für Ihre Einkauf!</strong><br /><br /> </td> </tr>
   <tr>
   <td><strong>*Alle Preise einschließlich MwSt.</strong><br /><br /><a href='formular.php'>zur&uuml;ck zum Formular</a></td>
   </tr></table>"
;
   echo 
"<br />";
    echo 
"<br />";
     echo 
"<br />";
      echo 
"<br />";
      
         
   echo 
"<hr align='center' width='825' size='7' color='#FF6600' />
   <table align='center'bgcolor='#FFFFCC'width='720' border='0' cellspacing='2' cellpadding='2'>
 <tr>
 <td><strong>Bitte Ihre Daten:</strong></td>
 </tr>
 <tr>
 <td>Anrede:</td>
 <td><select name='anrede'>
   <option name='anrede'>Anrede</option>
   <option name='frau'>Frau</option>
   <option name='herr'>Herr</option>
 </select></td>
 <td>Telefon:</td>
 <td><input name='telefon' /></td>
 </tr>
 <tr>
 <td>Nachname:</td>
 <td><input name='nachname' /></td>
 <td>E-Mail:</td>
 <td><input name='email' /></td>
 </tr>
 <tr>
 <td>Vorname:</td>
 <td><input name='vorname' /></td>
 <td>Fax:</td>
 <td><input name='fax' /></td>
 </tr>
 <tr>
 <td>Straße:</td>
 <td><input name='strasse' /></td>
 <td>PLZ:</td>
 <td><input name='plz' /></td>
 </tr>
 <tr>
 <td>Haus Nr.:</td>
 <td><input name='haus' /></td>
 <td>Ort:</td>
 <td><input name='ort' /></td>
 </tr>
 <tr>
 <td>Land:</td>
 <td><select name='land'>
   <option>Deutschland</option>
   <option>Österreich</option>
   <option>Schweiz</option>
   <option>Liechtenstein</option>
   <option>Spanien</option>
   <option>Italien</option>
   <option>Frankreich</option>
   <option>Belgien</option>
   <option>Niederlande</option>
   <option>Dänemark</option>
   <option>Andere</option>
 </select></td>
 <td>Sonstiges:</td>
 <td><textarea name='sonstiges' cols='50' rows='5'></textarea></td>
 </tr>
 <tr>
 <td class='agb'>Ich habe die AGB gelesen und akzeptiert</td>
 <td><input name='agb' type='checkbox' value='agb' checked /></td>
 </tr>
 
 <tr>
 <td><input name='abschicken' type='submit' value='Bestellung abschicken' /> <input type='button' name='drucken' value='drucken' onclick='window.print();'></td>
 </tr>
 

</table>"
;



?>
</form>
  #2 (permalink)  
Antiguo 03/12/2009, 06:09
 
Fecha de Ingreso: diciembre-2009
Mensajes: 3
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Ayuda con formulario

esta es el documento a donde va dirigido el formulario anterior, para que lo tengan a la vista por cualquier cosa


Código PHP:
<?php

$link 
mysql_connect("localhost","root","");
mysql_select_db("empresa_db"$link);
/*echo "<pre>";
print_r($_POST);
echo "</pre>";*/
$tc1k         =     $_POST['tc1k'];
$tc3k         =     $_POST['tc3k'];
$tc5k         =     $_POST['tc5k'];
$bio1f         =    $_POST['bio1f'];
$sjf         =    $_POST['sjf'];
$tvf        =    $_POST['tvf'];

$land            =    $_POST['land'];
$telefon        =    $_POST['telefon'];
$fax            =    $_POST['fax'];
$email            =    $_POST['email'];
$sonstiges        =    $_POST['sonstiges'];
$vorname        =    $_POST['vorname'];
$gesamtbetrag    =    $_POST['gesamtbetrag'];

$anrede        $_POST['anrede'];
$frau         $_POST['frau'];
$herr         $_POST['herr'];
$nachname     $_POST['nachname'];
$strasse     $_POST['strasse'];
$haus         $_POST['haus'];
$plz         $_POST['plz'];
$ort         $_POST['ort'];
$datum        date('Y') . '-' date('m') . '-' date('d');
$ip            $_SERVER['REMOTE_ADDR'];

$_POST['tc1k'];
$_POST['tc3k'];
$_POST['tc5k'];
$_POST['bio1f'];
$_POST['sjf'];
$_POST['tvf'];
$_POST['gesamtbetrag'];

$preis1 =   $_POST['tc1k']*9.70;
$preis2 =   $_POST['tc3k']*21.70;
$preis3 =   $_POST['tc5k']*35.70;
$preis4 =   $_POST['bio1f']*13.30;
$preis5 =   $_POST['sjf']*11.30;
$preis6 =   $_POST['tvf']*10.10;

$gesamt $preis1 $preis2 $preis3 $preis4 $preis5 $preis6;

$versandkostenpauschale $gesamt 6.9;

$gesamtbetrag $gesamt 6.9;

$preis1 number_format($preis12"," ".");
$preis2 number_format($preis22"," ".");
$preis3 number_format($preis32"," ".");
$preis4 number_format($preis42"," ".");
$preis5 number_format($preis52"," ".");
$preis6 number_format($preis62"," ".");

$versandkostenpauschale number_format($versandkostenpauschale2"," ".");
$gesamt number_format($gesamt2"," ".");
$gesamtbetrag number_format($gesamtbetrag2"," ".");

$befehl "INSERT INTO bestellung(tc1k, tc3k, tc5k, bio1f, sjf, tvf, gesamtbetrag, anrede, nachname, vorname, email, strasse, haus, plz, ort, land, telefon, fax, sonstiges, datum, ip)VALUES('$tc1k', '$tc3k', '$tc5k', '$bio1f', '$sjf', '$tvf', '$gesamtbetrag', '$anrede', '$nachname', '$vorname', '$email', '$strasse', '$haus', '$plz', '$ort', '$land', '$telefon', '$fax', '$sonstiges', '$datum', '$ip')";


 
if(
$anrede == 'frau')
{
echo 
"<table align='links' bgcolor='#8DCB41' width='720'> <tr height='50'> <td> Vielen Dank," $anrede $nachname " f&uuml;r Ihre Bestellung.</td></tr></table>";    
}
else 
{
echo 
"Vielen Dank" " " $anrede " " $nachname " f&uuml;r Ihre Bestellung. <br /> <br /> <br /> <br />";    
}


echo 
"<table  align='links'bgcolor='#FFFFCC'width='720' border='0' cellspacing='2' cellpadding='2'>
    <tr height='50'>
      <td class='text'>Ihre Einkauf in H&ouml;he von" 
" <strong>" $gesamtbetrag " &euro;</strong> wird von uns bearbeitet.  Sie erhalten Ihre Rechnung per E-Mail. Bitte geben Sie bei &Uuml;berweisungen daher immer als Verwendungszweck Ihre Rechnungsnummer an. Sie finden diesen Nummer auf Ihrer Rechnung</td>
      </tr>
    <tr height='50'>
      <td class='text'>Wir schicken Ihnen Ihre Bestellung an" 
" " $strasse " " $haus ", " $plz " " $ort " " " </td>
      </tr>
     <tr height='50'>
      <td class='text'>Sie k&ouml;nnen uns nach Ihrem Bestellungstatus zu jeder Zeit fragen.  Einfach senden Sie uns eine E-Mail.</td>
      </tr>
      <tr>
      <td> Ihre Team </td>
      <td><a href='seite.html'>Home</a><input type='button' name='drucken' value='drucken' onclick='window.print();'></td>
      </tr>
      </table>
      "
;


mysql_query($befehl$link);
echo 
mysql_error($link);
mysql_close($link);

?>
muchísimas gracias por toda la ayuda, de verdad me esto me ha tenido bastante ocupado y preocupado...
  #3 (permalink)  
Antiguo 03/12/2009, 07:09
Avatar de Fairy_Boy  
Fecha de Ingreso: octubre-2009
Ubicación: Kokiri Forest
Mensajes: 235
Antigüedad: 14 años, 6 meses
Puntos: 5
Respuesta: Ayuda con formulario

Hola neulig.
con respecto a tus dudas.
1° usa la funcion isset para verificar si un textbox fue llenado o no, luego es cosa de ponerlo en un if.

2° desconozco librerias para envio de correos, pero en el fro hay bastantes temas sobre eso, saludos!
  #4 (permalink)  
Antiguo 04/12/2009, 03:27
 
Fecha de Ingreso: diciembre-2009
Mensajes: 3
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Ayuda con formulario

muchas gracias Fairy_boy.

me daré una vuelta por el foro a ver que sale.

lo del isset lo probaré ya...


gracias otra vez
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:25.