Hirdetés
- iPhone topik
- Xiaomi 15T - reakció nélkül nincs egyensúly
- Xiaomi 14T Pro - teljes a család?
- Poco X6 Pro - ötös alá
- EarFun Air Pro 4+ – érdemi plusz
- Megérkezett a Google Pixel 7 és 7 Pro
- Milyen okostelefont vegyek?
- Az iPhone 17 gáncsolta el a Galaxy S26 Prót?
- Mobil flották
- Apple iPhone 17 Pro Max – fennsík
Új hozzászólás Aktív témák
-
válasz
lanszelot
#21060
üzenetére
Oké, megpróbáltam összedobni W3-ban, de nem jó ott a callback, viszont ez alapján látnod kellene mit kell csinálni:
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
// betöltés szimulálása
$array = array();
$array["google"] = ['kep' => "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", 'link' => "www.google.com"];
$array["startlap"] = ['kep' => "https://lap.hu/images/startlap-logo.png", 'link' => "www.lap.hu"];
// betöltés vége
// define variables and set to empty values
$nameErr = $kepErr = $linkErr = "";
$name = $kep = $link = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z_]*$/",$name)) {
$nameErr = "Only letters and underscore allowed";
}
}
if (empty($_POST["kep"])) {
$kepErr = "Email is required";
} else {
$kep = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$kep)){
$kepErr = "Invalid URL format";
$kep = "";
}
}
if (empty($_POST["link"])) {
$link = "";
} else {
$link = test_input($_POST["link"]);
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$link)) {
$linkErr = "Invalid URL";
$link = "";
}
}
if ($name > "" && $kep > "" && $link > "") {
$array[$name] = ['kep' => $kep, 'link' => $link];
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation Example</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name" value="">
<br><br>
Kep: <input type="text" name="kep" value="">
<br><br>
Link: <input type="text" name="link" value="">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<span class="error"><?php echo $nameErr;?></span>
<br><br>
<span class="error"><?php echo $kepErr;?></span>
<br><br>
<span class="error"><?php echo $linkErr;?></span>
<br><br>
<textarea>
<?php
var_dump($array);
?>
</textarea>
</body>
</html>
Új hozzászólás Aktív témák
- HIBÁTLAN iPhone 14 Pro Max 128GB Gold -1 ÉV GARANCIA - Kártyafüggetlen, MS3910, 100% Akksi
- AKCIÓ! Apple MacBook Pro 16 M4 Max 36GB RAM 1TB SSD macbook garanciával hibátlan működéssel
- Lenovo IdeaPad Slim 3 - 15.6" Full HD - Ryzen 5-7520U - 8GB - 512GB - Win11 PRO - MAGYAR - Garancia
- Microsoft Windows, Office & Vírusirtók: Akciók, Azonnali Szállítás, Garantált Minőség, Garancia!
- Azonnali készpénzes Intel i5 i7 i9 8xxx 9xxx processzor felvásárlás személyesen / csomagküldés
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Laptopműhely Bt.
Város: Budapest


