Pengaturan

Gambar

Lainnya

Tentang KASKUS

Pusat Bantuan

Hubungi Kami

KASKUS Plus

© 2024 KASKUS, PT Darta Media Indonesia. All rights reserved

crown.victoriaAvatar border
TS
crown.victoria
Cara memunculkan pop-up message dgn PHP
Hallo para master programmer
ane butuh pencerahan gan

ane skrg udah buat form untuk reservasi hotel gan. Codingnya kayak gini

Code:

<?php
include 'core/init.php';

protect_page();
include 'includes/overall/header.php' ;



//if form is being submitted
if(empty($_POST)=== false)
{
//to validate whether user enters smtg or not otherwise no point continue to do the next validation
//create an array
$required_fields = array ('user_id','fullname','contactno','passport','dor','dco');
foreach($_POST as $key=>$value)
{

//if the key (value) in array of $required_fields is true which is empty
if(empty($value) && in_array ($key, $required_fields) === true )
{
$errors[] = 'You must filled up all of the fields';
//the validation can happen to more than 1 field
break 1;
}
}

if(empty($errors) === true)

{
if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]S E N S O R[0-1])$/', $_POST['dor']))
{
?>
[removed]alert('Input date of reservation correctly');[removed]
<?php
exit();
}

else if (!preg_match('/^[a-z A-Z]{3,30}$/', $_POST['fullname']))
{
?>
[removed]alert('Input your full name correctly');[removed]
<?php
exit();
}

else if (!preg_match('/^[0-9]\d{9}$/', $_POST['contactno']))
{

?>
[removed]alert('Enter Contactno correctly');[removed]
<?php
exit();
}

else if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]S E N S O R[0-1])$/', $_POST['dco']))
{
?>
[removed]alert('Input your check-out date correctly');[removed]
<?php
exit();
}


else if (strtotime($_POST['dor']) < time())
{
?>
[removed]alert('Reservation date cannot in the past!!');[removed]
<?php
exit();
}

else if (strtotime($_POST['dco']) < strtotime($_POST['dor']))
{
?>
[removed]alert('Check-out date cannot before the reservation date!!');[removed]
<?php
exit();
}

}
}
//what does this line does is that to check whether success is in the end of the URL
if(isset($_GET['success']) && empty($_GET['success']))
{

view_reservation();

}
else
{//if there are no errors
if (empty($_POST) === false && empty($errors) === true)
{
check_availability();
}

//
else if (empty($errors) === false)
{
echo output_errors($errors);
}

?>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
[removed][removed]

[removed]
window.onload = function(){
new JsDatePick({
useMode:2,
target:"dor",
dateFormat:"%Y-%m-%d"

});

new JsDatePick({
useMode:2,
target:"dco",
dateFormat:"%Y-%m-%d"

});
};


[removed]



<h1 style="font-family: 'Gill Sans', 'Gill Sans MT', 'Myriad Pro', 'DejaVu Sans Condensed', Helvetica, Arial, sans-serif">RESERVATION </h1>

<span style="font-family: 'Gill Sans', 'Gill Sans MT', 'Myriad Pro', 'DejaVu Sans Condensed', Helvetica, Arial, sans-serif">

<form action="" method="post">
<fieldset>
</span>
<legend>
<span style="font-family: 'Gill Sans', 'Gill Sans MT', 'Myriad Pro', 'DejaVu Sans Condensed', Helvetica, Arial, sans-serif"><font size="6">Please input your information correctly</font> </span></legend>

<p>
<form action="" method="post" >
<ul>
<li>
Full name*: <br>
<input type="text" name="fullname">
</li>
<li>
Contact No.: <br>
<input type="text" name="contactno">
</li>
<li>
IC/Passport*: <br>
<input type="text" name="passport">
</li>
<li>
Room Type*: <br>
<select name="roomtype" id="roomtype">
<option value="">Select</option>
<option value="Single">Single (RM 100)</option>
<option value="Superior">Superior (RM 200)</option>
<option value="Deluxe">Deluxe (RM 300)</option>
</select>
</li>
<br>
<li>
Date of reservation*: <br>
<input type="text" size="12" id= "dor" name="dor"/>
</li>
<li>
Check-out Date*: <br>
<input type="text" size="12" id= "dco" name="dco"/>
</li>

<input type="submit" value="Submit">
<input type="reset" value="Clear" >
<li>
<br>
<br>
<br>
<br>
<br>
<br>
</ul>
</form>

<?php
}
include 'includes/overall/footer.php' ;
?>


btw removed itu script gan

Masalahnya, pas ane isi form yg salah, pop up muncul tapi halamannya malah jadi kosong gan. Jadi otomatis user harus ngisi form dari awal.
Gimana caranya kalo semisal kita salah isi form, pop up error muncul tanpa menghilangkan isi form gan

Thanks gan emoticon-Cendol (S)
0
2.6K
1
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Urutan
Terbaru
Terlama
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Komunitas Pilihan