<?php
require_once 'connection.php';
$slug = '';
if(isset($_POST["create"])){
$slug = preg_replace('/[^a-z0-9]+/i', '-', trim(strtolower($_POST["title"])));
$query = "SELECT slug_url FROM bn_publicacao WHERE slug_url LIKE '$slug%'";
$statement = $conn->prepare($query);
if($statement->execute()){
$total_row = $statement->rowCount();
if($total_row > 0){
$result = $statement->fetchAll();
foreach($result as $row){
$data[] = $row['slug_url'];
}
if(in_array($slug, $data)){
$count = 0;
while( in_array( ($slug . '-' . ++$count ), $data) );
$slug = $slug . '-' . $count;
}
}
}
$insert_data = array(
':title' => $_POST['title'],
':descricao' => $_POST['descricao'],
':capa' => $_POST['capa'],
':alt' => $_POST['alt'],
':keywords' => $_POST['keywords'],
':categoria' => $_POST['categoria'],
':slug_url' => $slug,
':slug_link' => $slug,
':entry_type' => $_POST['entry_type'],
);
$query = "INSERT INTO bn_publicacao (title, descricao, capa, alt, keywords, categoria, slug_url, slug_link, entry_type) VALUES (:title, :descricao, :capa, :alt, :keywords, :categoria, :slug_url, :slug_link, :entry_type)";
$statement = $conn->prepare($query);
$statement->execute($insert_data);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Form</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<style>
.box
{
max-width:600px;
width:100%;
margin: 0 auto;;
}
</style>
</head>
<body>
<div class="container box">
<br />
<h3 align="center">Gravar post</h3>
<br />
<form method="post">
<div class="form-group">
<label>Title</label>
<input type="text" name="title" class="form-control mb-3" required />
<label>Descicao</label>
<input type="text" name="descricao" class="form-control mb-3" required />
<label>Capa</label>
<input type="text" name="capa" class="form-control mb-3" required />
<label>Alt</label>
<input type="text" name="alt" class="form-control mb-3" required />
<label>Keywords</label>
<input type="text" name="keywords" class="form-control mb-3" required />
<label>Categoria</label>
<input type="text" name="categoria" class="form-control mb-3" required />
<label>Entry_type</label>
<input type="text" name="entry_type" class="form-control mb-3" required />
</div>
<br />
<div class="form-group">
<input type="submit" name="create" class="btn btn-info" value="Enviar" />
</div>
<br />
<h4>Generated Slug - <?php echo $slug; ?></h4>
</form>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</body>
</html>
input
“标题”会自动生成一个段,并将其发送到列slug_url
和slug_link
,我需要在slug_url
上一起发送默认字符串
我想在发芽到slug_url
列的子弹上添加默认网址。
示例:
我想将此网址默认添加到生成的“ http://example.com/”子弹中
这是-弹到列弹头URL
这就是应该将其发送到我的专栏slug_url
:
http://example.com/this-is-the-slug-gererated-to-the-column-slug-url
答案 0 :(得分:1)
非常简单,只需更改部分代码即可:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="Button" id='AddButton' value="+" />
<canvas id="myCanvas" width="500" height="100" style="border:1px solid #d3d3d3;">
注意,我刚刚更改了设置:slug_url列的行
答案 1 :(得分:1)
您可以添加这样的内容
':slug_url' => "https://example.com/".$slug,