|
[ ZeRo8 @ 22.06.2006. 14:49 ] @
| Pravim formu u phpu. Imam 4 PHP stranica firstStep.php, secondStep.php, thirdStep.php i viewAll.php.
Znaci forma se popunjava, korak po korak, kad se ispuni prvi korak i kad kliknem na CONTINUE on me salje na seconStep.php ....i tako dalje. Sve to ide s POST metodom.
Moje pitanje je: kako da radim refresh strane i da proverim da li su neka polja popunjena i da ako nisu ne ide na secondStep.php nego da me ostavi na istoj strani i da mi gore ispise da moram da popunim prvo odredjena polja? Ako moze sve s PHPom, JS ne poznajem.
hvala unapred |
[ Davor Grubelić @ 22.06.2006. 18:00 ] @
probaj sa:
Code:
if (isset($_post['continue']) and
isset($_post['polje1']) and
isset($_post['polje2']) and
isset($_post['polje3'])) {
//idi na drugu stranu
}
else {
//prikaži formu za unos podataka
}
i gore u formi stavi
Code:
<form action="<?php echo $_server['php_self']?>?prva_strana" method="post">
tako da ti stalno pravi loop na istu stranicu i ako zadovolji uvjet ode dalje. ja tako radim
[ Pharos @ 22.06.2006. 19:55 ] @
Nekad je JS validacija zahvalnija.
Code:
<script language="JavaScript">
<!-- Begin
function checkFields() {
T1 = (document.notify.T1.value);
T2 = (document.notify.T2.value);
if (T1 == "") {
alert("Please ensure that you entered your first name");
return false;
}
if (T2 == "") {
alert("Please ensure that you entered your last name");
return false;
}
else return true;
}
// End -->
</script>
<form method="POST" action="submit.php" name="notify" id="notify" onsubmit="return checkFields()">
<p>First Name(*) <input type="text" name="T1" size="20"></p>
<p>Last Name(*) <input type="text" name="T2" size="20"></p>
<p>Phone <input type="text" name="T3" id="T3" size="20"></p>
<p><input type="submit" value="Submit" name="B1"></p>
</form>
Znači imaš 3 txt polja (T1, T2, T3) koja post metodom šalješ na submit.php stranicu.
Polja T1 i T2 su ti obavezna i ako ih ne popuniš, ne možeš podatke da proslediš drugoj stranici.
[ Nemanja Avramović @ 22.06.2006. 19:59 ] @
Naravno, ako radiš nešto ozbiljnije gde su u pitanju neki važni podaci ili tako nešto, radi i javascript i php validaciju jer se ova javascript validacija može relativno lako zaobići.
Pozdrav
[ ZeRo8 @ 22.06.2006. 22:17 ] @
Kako da napravim to da odem na drugu stranu
hvala
[ kelja @ 22.06.2006. 22:37 ] @
Header("Location:drugastrana.php");
[ ZeRo8 @ 22.06.2006. 22:58 ] @
Citat: kelja: Header("Location:drugastrana.php");
Imam ovako:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>First step of registration</title>
<link REL="StyleSheet" TYPE="text/css" HREF="/styles.css">
<body>
<!--Including Head-->
<?php include('http://localhost/learn-german/head.html'); ?>
<!--Checking the input-->
<?php
if (isset($_post['continueButton']) and
isset($_post['firstName']) and
isset($_post['lastName'])) {
header("Location:http://localhost/a/myRegistrationForm/secondStep.php");
}
else {
?>
<form action="<?php echo $_server['php_self']?>?firstStep.php" method="POST" name="firstStepForm">
.
.
.
.
Sta tu ne valja. Javlja mi server gresku:
Forbidden
You don't have permission to access /a/myRegistrationForm/<br /><b>Notice</b>: Undefined variable: _server in <b>c:\dokumente und einstellungen\zero8\desktop\apachedata\a\myregistrationform\firststep.php</b> on line <b>40</b><br /> on this server.
Apache/1.3.33 Server at localhost Port 80
[ kelja @ 23.06.2006. 06:41 ] @
E vidi...redirekcija treba da se nalazi u kodu pre bilo kog drugog outputa
"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file...".A u kodu dole imas i nezatvorenu zagradu...A i svejedno-nisam siguran da ce to sa redirekcijom ici...
Nego da zamolimo Davora da nam jos malo pojasni ovaj red:
Code: <form action="<?php echo $_server['php_self']?>?prva_strana" method="post">
[ ZeRo8 @ 23.06.2006. 07:10 ] @
Hvala na odgovoru u vezi HEADERA
Inace ono sto je Davor napisao poziva istu stranu PHP_SELF i daje joj ?prvastrana.php sve podatke iz te strane koje si uneo u polja. Tako sam ja bar razumeo :)
poz
[ ZeRo8 @ 23.06.2006. 08:15 ] @
Jos jedno pitanje u vezi formulara.
Imam na jednoj php strani koja je u vezi sa formularom select meni u kome mi se nalaze razliciti "kursevi jezika". Kad izaberem jedan u tom select meniju, trebalo bi da mi odmah dole kreira jos jedan select meni (DATUM, tj. pocetak kursa) koji je vezan za odredjenji kurs.
Znaci ako imam u prvom select meniju (kurs nemackog, kurs engleskog, kurs ....) on bi trebao kad ja izaberem "kurs nemackog" da mi kreira jos jedan takav select meni ispod njega gde ce biti 1. Oktober, 2. Novembar ....
U sustini ne mora da se u letu kreira novi select meni, jednostavno da mi se u okviru tog novog koji je vec definisan samo promene datumi (vezani za odredjeni kurs)
Ako ne razumete sta sam mislio, probacu da objasnim bolje :)
Sta se koristi u ovo slucaju???
hvala unapred
[ Davor Grubelić @ 23.06.2006. 11:38 ] @
Citat: ZeRo8: Jos jedno pitanje u vezi formulara.
Imam na jednoj php strani koja je u vezi sa formularom select meni u kome mi se nalaze razliciti "kursevi jezika". Kad izaberem jedan u tom select meniju, trebalo bi da mi odmah dole kreira jos jedan select meni (DATUM, tj. pocetak kursa) koji je vezan za odredjenji kurs.
Znaci ako imam u prvom select meniju (kurs nemackog, kurs engleskog, kurs ....) on bi trebao kad ja izaberem "kurs nemackog" da mi kreira jos jedan takav select meni ispod njega gde ce biti 1. Oktober, 2. Novembar ....
U sustini ne mora da se u letu kreira novi select meni, jednostavno da mi se u okviru tog novog koji je vec definisan samo promene datumi (vezani za odredjeni kurs)
Ako ne razumete sta sam mislio, probacu da objasnim bolje :)
naravno ovo se sve izvršava na index.php tako da ti nisu opotrebne 4 različite stranice
Sta se koristi u ovo slucaju???
hvala unapred
opet javascript
ili ajax (ajax je javascript+xml)
e sad da pojasnimo....
znači klikneš na link za ispunjavanje forme i on te odvede na http://localhost/moj_web/index.php?prva_strana i na toj strani je forma sa kodom dolje
Code:
<form action="<?php echo $_SERVER['PHP_SELF']?>?prva_strana" method="post">
kad klikneš na continue skripta provjerava da li su unesena potrebna polja. ako jesu prelazi na drugu stranu, a ako nisu vraća te ponovo na http://localhost/moj_web/index.php?prva_strana
a što se samog koda tiče on generira link http://localhost/moj_web/index.php?prva_strana
ovo je slučaj kada se u u index.php include-aju drugi file-ovi.
a ako ideš na način da otvaraš zasebne stranice onda
Code:
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
[Ovu poruku je menjao Davor Grubelić dana 23.06.2006. u 14:14 GMT+1]
[ ZeRo8 @ 23.06.2006. 14:22 ] @
Hvala na objasnjenju, sve radi kako treba. Jos me samo jedno zanima.
Kad je neko recimo uneo sve odatke i na kraju hoce da promeni nesto od onog sto je uneo, kako da me vrati na onu prvu stranicu preko BUTTONa i da svi podaci koji su prethodno bili uneseni ostanu tamo, tako da neko moze samo da obrise ono gde je napravio gresku?
[ kelja @ 23.06.2006. 15:07 ] @
@zero 8
Hajde budi ljubazan pa posalji ovde ceo kod...Moze i kao attachment ako nije problem...
[ Davor Grubelić @ 23.06.2006. 15:10 ] @
da bi se mogao vratiti nazad i promjeniti nešto, moraš prvo podatke spremiti u recime $_SESSION varijablu (polje). i onda moraš postaviti u polje za upis (recimo "ime") :
Code:
//ispiše polje sa vrijednosti sessiona
<input type="text" name="ime" value="<?php if(isset($_SESSION['ime'])) { echo $_SESSION['ime'];}?>">
[ ZeRo8 @ 23.06.2006. 16:10 ] @
Hvala puno davore pozabavicu se time.
[ ZeRo8 @ 23.06.2006. 16:31 ] @
Citat: Davor Grubelić: da bi se mogao vratiti nazad i promjeniti nešto, moraš prvo podatke spremiti u recime $_SESSION varijablu (polje). i onda moraš postaviti u polje za upis (recimo "ime") :
Code:
//ispiše polje sa vrijednosti sessiona
<input type="text" name="ime" value="<?php if(isset($_SESSION['ime'])) { echo $_SESSION['ime'];}?>">
Gde trebam postaviti SESSION? Na svakoj strani na dnu forme ili ... gde vec. A na poslednjoj strani imam BUTTON "change" koji mi u onClick otvara novu stranicu, mislim da tako nece ici. Sta bi inace trebalo biti u "onClick"
[ Davor Grubelić @ 23.06.2006. 16:55 ] @
session postavljaš na vrhu stranice, prije bilo čega.. znači:
Code:
<?php
session_start();
i onda ostatak koda..
i ako otvaraš zasebne strane moraš postavit na svaku.a ako ih include-aš u jednu onda samo u strani u koju include-aš ostalo.
ajd postaj kod pa da vidim, ne mogu ovako nasljepo ti baš puno reć.
[ ZeRo8 @ 23.06.2006. 17:09 ] @
evo koda
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>First step of registration</title>
<link REL="StyleSheet" TYPE="text/css" HREF="/styles.css">
<link rel="stylesheet" href="/js/calendar/themes/aqua.css" />
<!-- Loading Calendar JavaScript files -->
<script type="text/javascript" src="/js/calendar/src/utils.js"></script>
<script type="text/javascript" src="/js/calendar/src/calendar.js"></script>
<script type="text/javascript" src="/js/calendar/src/calendar-setup.js"></script>
<!-- Loading language definition file -->
<script type="text/javascript" src="/js/calendar/lang/calendar-en.js"></script>
<script language="JavaScript">
<!-- Begin
function validateEmail (valfield, // element to be validated
infofield, // id of element to receive info/error msg
required) // true if required
{
var stat = commonCheck (valfield, infofield, required);
if (stat != proceed) return stat;
var tfld = trim(valfield.value); // value of field with whitespace trimmed off
var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
if (!email.test(tfld)) {
msg (infofield, "error", "ERROR: not a valid e-mail address");
setfocus(valfield);
return false;
}
var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/ ;
if (!email2.test(tfld))
msg (infofield, "warn", "Unusual e-mail address - check if correct");
else
msg (infofield, "warn", "");
return true;
}
function checkFields() {
checkSex = (document.firstStepForm.sex.value);
checkFirstName = (document.firstStepForm.firstName.value);
checkLastName = (document.firstStepForm.lastName.value);
checkBirth = (document.firstStepForm.birth.value);
checkStreet = (document.firstStepForm.street.value);
checkZip = (document.firstStepForm.zip.value);
checkTown = (document.firstStepForm.town.value);
checkCountry = (document.firstStepForm.country.value);
checkNationality = (document.firstStepForm.nationality.value);
checkEmail = (document.firstStepForm.email.value);
if (checkSex == "") {
alert("Please ensure that you entered Sex");
return false;
}
if (checkFirstName == "") {
alert("Please ensure that you entered your first name");
return false;
}
if (checkLastName == "") {
alert("Please ensure that you entered your last name");
return false;
}
if (checkBirth == "") {
alert("Please ensure that you entered your Birth");
return false;
}
if (checkStreet == "") {
alert("Please ensure that you entered Street where you live");
return false;
}
if (checkZip == "") {
alert("Please ensure that you entered your Postal Code / ZIP");
return false;
}
if (checkTown == "") {
alert("Please ensure that you entered your Town");
return false;
}
if (checkCountry == "") {
alert("Please ensure that you entered your Country");
return false;
}
if (checkNationality == "") {
alert("Please ensure that you entered your Nationality");
return false;
}
if (checkEmail == "" ) {
alert("Please ensutre that you entered your Email");
return false;
}
else return true;
}
// End -->
</script>
</head>
<body>
<!--Including Head-->
<?php include('http://localhost/learn-german/head.html'); ?>
<form method="POST" action="secondStep.php" name="firstStepForm" id="firstStepForm" onsubmit="return checkFields()">
<table align="center" class="formular" style="margin-top:20px;">
<tr>
<td align="right"><img src="../MyHomepage/my/images/formStepsFotoStep1.jpg" alt="firstStep" width="190" height="14" /></td>
</tr>
</table>
<table align="center" class="formular" style="margin-top:20px; border-bottom-style:none">
<tr>
<td>
<div style="text-align:center; color:#7F9DB9; font-weight:bold; font-size:14px; font-family:Arial, Helvetica, sans-serif;" >Personal Informations</div>
</td>
</tr>
</table>
<table align="center" class="formular">
<tr>
<td width="175" class="formular">Sex * </td>
<td width="145" style="color:#0033CC" class="formular">
<input class="myBox" type="radio" name="sex" value="Female" checked="checked" />
Female
<input class="myBox" type="radio" name="sex" value="Male" />
Male
<br />
</td>
</tr>
<tr>
<td class="formular">First Name * </td>
<td class="formular">
<input class="myBox" type="text" name="firstName" tabindex="3" value="<?php if(isset($_SESSION['firstName'])) { echo $_SESSION['firstName'];}?>" /></td>
</tr>
<tr>
<td class="formular">Last Name * </td>
<td class="formular"><input class="myBox" type="text" name="lastName" tabindex="4" /></td>
</tr>
<tr>
<td class="formular">Date of Birth * </td>
<td class="formular"><input class="myBox" type="text" name="birth" tabindex="5" />
</td>
</tr>
<tr>
<td class="formular">Street * </td>
<td class="formular"><input class="myBox" type="text" name="street" tabindex="6" /></td>
</tr>
<tr>
<td class="formular">Postal Code / ZIP * </td>
<td class="formular"><input class="myBox" type="text" name="zip" tabindex="7" /></td>
</tr>
<tr>
<td class="formular">Town * </td>
<td class="formular"><input class="myBox" type="text" name="town" tabindex="8" /></td>
</tr>
<tr>
<td class="formular">Country * </td>
<td class="formular"><input class="myBox" type="text" name="country" tabindex="9" /></td>
</tr>
<tr>
<td class="formular">Nationality * </td>
<td class="formular"><input class="myBox" type="text" name="nationality" tabindex="10" /></td>
</tr>
<tr>
<td class="formular">Place of Birth </td>
<td class="formular"><input class="myBox" type="text" name="placeOfBirth" tabindex="11" /></td>
</tr>
<tr>
<td class="formular">Phone </td>
<td class="formular"><input class="myBox" type="text" name="phone" tabindex="12" /></td>
</tr>
<tr>
<td class="formular">Fax</td>
<td class="formular"><input class="myBox" type="text" name="fax" tabindex="13" /></td>
</tr>
<tr>
<td class="formular">Profession</td>
<td class="formular"><input class="myBox" type="text" name="profession" tabindex="14" /></td>
</tr>
<tr>
<td class="formular">Email * </td>
<td class="formular"><input class="myBox" type="text" name="email" tabindex="15" /></td>
</tr>
<tr>
<td class="formular">
<br /><br />
<input type="hidden" name="send" value="true" class="myBox">
<input class="myFormularContinueButton" type="submit" name="continueButton" value="Continue">
<input class="myFormularContinueButton" type="reset" name="resetButton" value="Reset" />
</td>
</tr>
</table>
</form>
<!--Including Tail-->
<?php include('http://localhost/learn-german/tail.html'); ?>
</body>
</html>
To je prva stranica, onda idu jos dve posle nje s slicnim kontekstom, i na kraju je stranica gde korisnik moze kliknuti na EDIT:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Third step off registration</title>
<link REL="StyleSheet" TYPE="text/css" HREF="/styles.css">
</head>
<body>
<?php include('http://localhost/learn-german/head.html'); ?>
<table align="center" class="formular" style="margin-top:20px; border-bottom:none;">
<tr>
<td>
<div style="text-align:center; color:#7F9DB9; font-weight:bold; font-size:14px; font-family:Arial, Helvetica, sans-serif;" >You have provided following informations</div>
</td>
</tr>
<table align="center" class="formular">
<tr>
<td width="175" class="formular">Sex </td>
<td width="145" class="formularBlueText"><?php print "{$_POST['sex']}"; ?></td>
</tr>
<tr>
<td class="formular">First Name </td>
<td class="formularBlueText"><?php print "{$_POST['firstName']}"; ?></td>
<tr>
<td class="formular">Last Name * </td>
<td class="formularBlueText"><?php print "{$_POST['lastName']}"; ?></td>
</tr>
<tr>
<td class="formular">Date of Birth * </td>
<td class="formularBlueText"><?php print "{$_POST['birth']}"; ?></td>
</tr>
<tr>
<td class="formular">Street * </td>
<td class="formularBlueText"><?php print "{$_POST['street']}"; ?></td>
</tr>
<tr>
<td class="formular">Postal Code / ZIP * </td>
<td class="formularBlueText"><?php print "{$_POST['zip']}"; ?></td>
</tr>
<tr>
<td class="formular">Town * </td>
<td class="formularBlueText"><?php print "{$_POST['town']}"; ?></td>
</tr>
<tr>
<td class="formular">Country * </td>
<td class="formularBlueText"><?php print "{$_POST['country']}"; ?></td>
</tr>
<tr>
<td class="formular">Nationality * </td>
<td class="formularBlueText"><?php print "{$_POST['nationality']}"; ?></td>
</tr>
<tr>
<td class="formular">Place of Birth </td>
<td class="formularBlueText"><?php print "{$_POST['placeOfBirth']}"; ?></td>
</tr>
<tr>
<td class="formular">Phone </td>
<td class="formularBlueText"><?php print "{$_POST['phone']}"; ?></td>
</tr>
<tr>
<td class="formular">Fax</td>
<td class="formularBlueText"><?php print "{$_POST['fax']}"; ?></td>
</tr>
<tr>
<td class="formular">Profession</td>
<td class="formularBlueText"><?php print "{$_POST['profession']}"; ?></td>
</tr>
<tr>
<td class="formular">Email * </td>
<td class="formularBlueText"><?php print "{$_POST['email']}"; ?></td>
</tr>
<tr>
<td class="formular">Course Typ *</td>
<td class="formularBlueText"><?php print "{$_POST['courseList']}"; ?></td>
</tr>
<tr>
<td class="formular">Course Date *</td>
<td class="formularBlueText"><?php print "{$_POST['dateList']}"; ?></td>
</tr>
<tr>
<td class="formular">How many weeks *</td>
<td class="formularBlueText"><?php print "{$_POST['courseWeeks']}"; ?></td>
</tr>
<tr>
<td class="formular">German Knowledge *</td>
<td class="formularBlueText"><?php print "{$_POST['knowledgeList']}"; ?></td>
</tr>
<tr>
<td class="formular">Accommodation </td>
<td class="formularBlueText"><?php print "{$_POST['accommodationType']}"; ?></td>
</tr>
</table>
<?php include('http://localhost/learn-german/tail.html'); ?>
</body>
</html>
Sta trebam jos uraditi i kod zadnje stranice?
[ Davor Grubelić @ 23.06.2006. 18:12 ] @
znači pokreneš session, i postaviš kod svakog polja
$_SESSION["polje1"] = $_POST["polje1"]
$_SESSION["polje2"] = $_POST["polje2"]
$_SESSION["polje3"] = $_POST["polje3"]
.
.
.
.
.
.
i onda ako hoćeš nesto promjenit
Code:
<input type="text" name="ime" value="<?php if(isset($_SESSION["polje1"])) { echo $_SESSION["polje1"];}?>">
nadam se da si me razumio
[ ZeRo8 @ 14.07.2006. 11:29 ] @
Jos jedno pitanje...
Kako resiti problem session-a i Back Buttona. Kad ispunim formu i kliknem na continue on mi otvori novu stranicu, i sad ako kliknem na BACK u Browseru on mi sve podatke iz forme izbrise (ukoliko na toj strani imam session_start(); kad toga nema onda je ok).
Gledao sam malo po netu i jedino sto sam nasao je da saljem Session ID na svaku narednu stranu ... ali ne uspeva mi...
Sta treba uraditi?
Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|