![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 55 Pomógł: 0 Dołączył: 21.09.2007 Skąd: Mielec Ostrzeżenie: (0%) ![]() ![]() |
Witam,
Wiem, że problem przewijał się już na forum, ale mam tutaj konkretną budowę skryptu: Otóż chcę zrobić, aby w jednym formularzu było zapisywanie i wypisywanie do newslettera naraz. A to moje wypociny, ale niestety nie działają jak trzeba: Kod <form name="txtlist" action="./index.php" target="txtlist" method="get" onsubmit="javascript:window.open('','txtlist','width=300,height=150,toolbar=no,status=no,resizable=no')">
<table border="0" cellpadding="4" cellspacing="0" bgcolor="#efefef" style="border: #dedede 3px double;"> <tr><td> <input type="hidden" name="type" value="sub"/> <input type="hidden" name="type" value="unsub"/> <input type="text" name="email" value="email address" size="20" maxlength="100" onfocus="if (this.value=='email address') this.value=''" onblur="if (this.value=='') this.value='email address'"/> <input type="submit" name="sub" value="subscribe"/> <input type="submit" name="unsub" value="unsubscribe"/> </td></tr> </table> Ten post edytował kamil881 29.01.2009, 12:51:28 |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 286 Pomógł: 70 Dołączył: 13.01.2009 Ostrzeżenie: (0%) ![]() ![]() |
Może zmieniaj wartość atrybutu action w zależności od akcji:
http://forum.php.pl/index.php?s=&showt...st&p=564293 |
|
|
![]()
Post
#3
|
|
![]() Grupa: Zarejestrowani Postów: 65 Pomógł: 2 Dołączył: 28.01.2009 Skąd: Opole Ostrzeżenie: (0%) ![]() ![]() |
Witam, Wiem, że problem przewijał się już na forum, ale mam tutaj konkretną budowę skryptu: Otóż chcę zrobić, aby w jednym formularzu zrobić zapisywanie i wypisywanie do newslettera naraz. A to moje wypociny, ale niestety nie działają jak trzeba: Kod <form name="txtlist" action="./index.php" target="txtlist" method="get" onsubmit="javascript:window.open('','txtlist','width=300,height=150,toolbar=no,status=no,resizable=no')"> <table border="0" cellpadding="4" cellspacing="0" bgcolor="#efefef" style="border: #dedede 3px double;"> <tr><td> <input type="hidden" name="type" value="sub"/> <input type="hidden" name="type" value="unsub"/> <input type="text" name="email" value="email address" size="20" maxlength="100" onfocus="if (this.value=='email address') this.value=''" onblur="if (this.value=='') this.value='email address'"/> <input type="submit" name="sub" value="subscribe"/> <input type="submit" name="unsub" value="unsubscribe"/> </td></tr> </table> Wcale się im nie dziwię ![]() Usuń te 2 linijki Kod <input type="hidden" name="type" value="sub"/> <input type="hidden" name="type" value="unsub"/> Skupmy się na 2 submit'ach. Wciśnięty submit również przekazuje wartość [przez POST], tak więc pliku index.php kiedy odbierasz dane zrób coś takiego:
Ten post edytował Kamil Jura 29.01.2009, 13:12:20 -------------------- Agencja Interaktywna ENERO - Strony www, reklama, identyfikacja wizualna - www.enero.com.pl
|
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 55 Pomógł: 0 Dołączył: 21.09.2007 Skąd: Mielec Ostrzeżenie: (0%) ![]() ![]() |
To jest plik index.php
Dodać to tu gdzieś po prostu? Kod <?
require('config.inc.php'); require('functions.inc.php'); // Max execution time of script. This does not include sleep time, so only restricts time // allowed for mailing. set_time_limit(3600); $type = $_GET['type']; $addr = stripslashes(urldecode($_GET['email'])); if ($type == 'sub') { // subscribe address. Actually, all it does is send the confirmation email if (!preg_match('#^([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+[^\".,?! ])$#i', $addr)) { $err = 'Your email address appears to be invalid.'; } if (!isset($err)) { $f = openfile($cfg['listfile']); $exists = false; while ($item = readitem($f)) { if ($item['addr'] == $addr) {$exists = true;break;} } if ($exists) { $err = 'That address is already subscribed to the list.'; } } if (!isset($err)) { // send confirmation email $headers = 'From: '.$cfg['from']; if ($cfg['headers']) { foreach ($cfg['headers'] as $val) $headers .= "\n".$val; } $headers .= "\n".$cfg['header_plain']; if (!@mail($addr, $cfg['subj_conf'], sprintf($cfg['msg_conf'], '?type=confirm&email='.urlencode($addr)), $headers)) { $err = 'There was an error sending the confirmation email. Please try again later.'; } } if (!isset($err)) { // confirmation sent if (isset($cfg['returnto_conf']) && $cfg['returnto_conf'] != '') { header('Location: '.$cfg['returnto_conf']); } else { printf($cfg['template'], 'Awaiting confirmation', 'An email has been sent to your address, '.$addr.', with a URL you must visit to confirm your subscription.'); } } else { // problem with subscription echoerr($err); } } elseif ($type == 'unsub') { // unsubscribe address $f = openfile($cfg['listfile']); $exists = false; while ($item = readitem($f)) { if ($item['addr'] == $addr) {$exists = true;break;} } if ($exists) { delitem($f, $item['id']); } else { $err = 'That address was not found.'; } if (!isset($err)) { // unsubscribe successful if (isset($cfg['returnto_unsub']) && $cfg['returnto_unsub'] != '') { header('Location: '.$cfg['returnto_unsub']); } else { printf($cfg['template'], 'Unsubscribed', 'Your address, '.$addr.' has successfully been unsubscribed from our mailing list.'); } } else { // problem with unsubscription echoerr($err); } } elseif ($type == 'confirm') { // subscribe a confirmed address if (!preg_match('#^([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)?[\w]+[^\".,?! ])$#i', $addr)) { $err = 'Your email address appears to be invalid. If you are pasting the URL from your confirmation email, make sure the URL wasn\'t split into two lines.'; } if (!isset($err)) { $f = openfile($cfg['listfile']); $exists = false; while ($item = readitem($f)) { if ($item['addr'] == $addr) {$exists = true;break;} } if ($exists) { $err = 'That address is already subscribed to the list.'; } } if (!isset($err)) { // subscribe successful writeitem($f, $addr); if (isset($cfg['returnto_sub']) && $cfg['returnto_sub'] != '') { header('Location: '.$cfg['returnto_sub']); } else { printf($cfg['template'], 'Subscribed', 'Your address, '.$addr.', is now subscribed to our mailing list!'); } } else { // problem with subscription echoerr($err); } } function echoerr($err) { printf($GLOBALS['cfg']['template'], 'Error', '<font color="red">Error: '.$err.'</font>'); } ?> |
|
|
![]()
Post
#5
|
|
![]() Grupa: Zarejestrowani Postów: 65 Pomógł: 2 Dołączył: 28.01.2009 Skąd: Opole Ostrzeżenie: (0%) ![]() ![]() |
Tutaj to wywal i napisz to co Ci podałem. Możesz w to wtoczyć jeszcze tego preg_match i tyle. A zmienne superglobalne z $_GET zamień na $_POST. Kombinuj. Powinno działać * Żeby nie pisać nowego posta: Zrobiłem edit w powyższym temacie. Tamten kod powinien działać:) Pozdrawiam Ten post edytował Kamil Jura 29.01.2009, 13:13:03 -------------------- Agencja Interaktywna ENERO - Strony www, reklama, identyfikacja wizualna - www.enero.com.pl
|
|
|
![]()
Post
#6
|
|
Grupa: Zarejestrowani Postów: 55 Pomógł: 0 Dołączył: 21.09.2007 Skąd: Mielec Ostrzeżenie: (0%) ![]() ![]() |
Wywala mi błąd w tej linijce:
Kod if(isset($_POST['type'] && $_POST['type'] == 'sub') {
|
|
|
![]()
Post
#7
|
|
![]() Grupa: Moderatorzy Postów: 36 557 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
1) Jak ci wywala blad, to nalezy go podac!!!
2)
3) Stosuj wlasciwe bbcode czyli [php] dla kodu php a nie [code] -------------------- "Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista "Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer |
|
|
![]()
Post
#8
|
|
Grupa: Zarejestrowani Postów: 55 Pomógł: 0 Dołączył: 21.09.2007 Skąd: Mielec Ostrzeżenie: (0%) ![]() ![]() |
Ok, dzięki. Myślę, że teraz już sobie poradzę.
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 19.08.2025 - 06:26 |