1

Всем добрый день.В файле index.php есть ссылка которая ведёт на другой файл (db.php) через который добавляется новая запись в бд.(<td colspan="3"><a href="db.php">Добавить клиента</a> </td> ) Как мне сделать чтобы при нажатии на ссылку в файле index.php в модальном окне открывалась форма db.php ? Помогите пожалуйста.

Вот файл index.php:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Рекламное агенство</title>
      <style type="text/css">
      <? include "css/style.css" ?>

      </style>

</head>
<body> 

    <?php 
$connection=mysql_connect("localhost","reklama","reklama") ;
$db=mysql_select_db(reklama);
mysql_set_charset("utf8");
if (!$connection || !$db)
{
exit(mysql_error());
}
$rezult=mysql_query("SELECT * FROM klienti");
mysql_close();
?>

<table align="center" >
<!--    <tr>Информация о клиентах</tr> -->
<tr  id="Add"  > 
   <td colspan="3"><a  href="db.php">Добавить клиента</a>  </td>
   <td colspan="3"><a  href="delete.php">Удалить клиента</a>  </td>
   <td colspan="3"><a  href="edit.php">Редактировать клиента</a>  </td>

</tr > 
<tr > 
<td id= "header"colspan="9"><b><font size="4" face="Arial" >Информация о клиентах </font></b></td>  <!--  тут растягиваем на 8 столбиков -->
</tr >

<tr >
     <th>Номер заказа </th>
     <th>Клиент </th>
     <th >ОП форма </th >
      <th >Наименование </th >
     <th>Отрасль </th >
     <th >Телефон </th >
      <th >Email </th >
     <th>Контактное лицо </th>
     <th >Должность </th >
     <th > Дата выполнения</th >
     <th >Дата добавления </th >
     <th >Время </th >
      <th >Действия </th >
      <!-- <th >Действия </th > -->
 </tr>
 <?php 
 while ($row=mysql_fetch_array($rezult)) 
{ ?> 
  <tr>
  <td><?php echo $row['id']?></td>
  <td><?php echo $row['klient']?></td>
    <td><?php echo $row['op_forma']?></td>
    <td><?php echo $row['naimen']?></td>
     <td><?php echo $row['otrasl']?></td>
    <td><?php echo $row['telefon']?></td>
    <td><?php echo $row['email']?></td>
     <td><?php echo $row['kont_lico']?></td>
 <td><?php echo $row['dolznost']?></td>
 <td><?php echo DateTime::createFromFormat("Y-m-d",$row['date1'])->format('d-‌​m-Y');?></td>
 <td><?php echo DateTime::createFromFormat("Y-m-d",$row['date'])->format('d-‌​m-Y');?></td>

 <td><?php echo $row['time']?></td>
 </tr>
 <?php } ?> 
</table>
 <!--      </section> -->

     <!-- Footer -->
    <!--  <footer>
     <div class="wrapper"> 

     </div>
     </footer> -->

</body>
</html> 

Вот файл db.php

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="calendar/tcal.js"></script> <!-- //календарь -->
<link rel="stylesheet" type="text/css" href="calendar/tcal.css" /> <!-- //календарь -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Добавление клиента</title>
<script  src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<!-- include the script -->
<script src="alertifyjs/alertify.min.js"></script>
<!-- include the style -->
<link rel="stylesheet" href="alertifyjs/css/alertify.min.css" />
<!-- include a theme -->
<link rel="stylesheet" href="alertifyjs/css/themes/default.min.css" />

<script type="text/javascript">
$("document").ready(function() {
$ ("form").submit(function(event){
    event.preventDefault(); // !!!
    var dannie = $("form").serialize();
    $.ajax({
        url:'insert.php',
        type: 'POST',
        data: dannie,
        success: function (data) {
            if (data) {

                  alertify.set('notifier','position', 'top-right');
                  alertify.success('Клиент успешно добавлен!'); 

 // alertify.success('Current position : ' + alertify.get('notifier','position'));
                      } 
            else {          
            alertify.alert("Ошибка");
                 }
                }
});
});
});
</script>
</head>
<body>
<form>
клиент<br/>
<input type="text" name="klient" /><br/>
ОП_форма <br/>
<textarea name="op_forma" ></textarea> <br/> <!-- cols="10" rows="10" -->
Наимен <br/>
<input type="text" name="naimen"  /><br/><br/>
отрасль <br/>
<input type="text" name="otrasl"  /><br/><br/>
telefon <br/>
<input type="text" name="telefon"  /><br/><br/>
email <br/>
<input type="text" name="email"  /><br/><br/>
Контактное лицо <br/>
<input type="text" name="kont_lico"  /><br/><br/>
Должность <br/>
<input type="text" name="dolznost"  /><br/><br/>
<input type="hidden" name="date" value="<?php echo date ('Y-m-d');?>" />
<input type="hidden" name="time" value="<?php echo date ('H:i:s');?>" />
<br/>
<input type="text" name="date1" class="tcal"  value="" />
<br/>
<br/>
<input type="submit"  id="send"  value="Добавить" />
<input type="button" name="reset_form" value="Очистить форму" onclick="this.form.reset();">
</form>
</body>
</html>

2 ответа 2

1

можно с помощью https://jqueryui.com/dialog/#modal-form сделать красиво, но нужно немного переписать код и смерджить оба файла. если мерджить не хочется - можно простым include-ом сделать в DIV. Или на js написать подгрузку странички в DIV при нажатии на ссылку.

В общем на Ваш вкус :)

3
  • можно простым include-ом сделать в DIV А как это сделать? есть инструкция какая?
    – roman
    1 окт 2016 в 18:24
  • @roman , пример: <div id="right"> <script> document.write('<?php echo include_once "include.php";?>'); </script> </div>
    – Relajado
    1 окт 2016 в 19:58
  • 1
    @roman вот есть еще
    – Relajado
    1 окт 2016 в 20:01
1

1) Самое простое - указать target

<a  href="db.php" target="_blank">Добавить клиента</a>

2) Чуть сложнее и менее надёжно - windows.open

<a id="addclient" href="db.php">Добавить клиента</a>

<script>
  $(document).ready(function(){
    $("#addclient").click(function(){
      var newWin = window.open("db.php", "newWinName", "");
       newWin.focus();
       return false;
    });
  });
</script>

3) Наиболее сложный способ - переписать db.php и загружать в div, "эмулирующий" окно.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.