Code: Select all
<form action="newtopic.php" method="POST">
<p><input class="topic-name" type="text" placeholder="Topic name" name="topic" id="topicInput" onkeyup="duplicate()"/></p>
<p><textarea class="content" placeholder="Text" name="content" id="contentInput"></textarea></p>
<p><input class="submitButton" type="submit" value="Submit form"/></p>
</form>
Code: Select all
$stringURL = $_POST['topic'];
$stringURL = preg_replace('/[^\\pL0-9]+/u', '-', $stringURL);
$stringURL = trim($stringURL, "-");
$stringURL = iconv("utf-8", "us-ascii//TRANSLIT", $stringURL);
$stringURL = preg_replace('/[^-a-z0-9]+/i', '', $stringURL);
$stringURL = strtolower($stringURL);
I used this function but the result is that it will print whole function text into textfield, instead of edited stringURL.
Code: Select all
<script type="text/javascript">
function duplicate(){
var id = document.getElementById('topicInput').value;
var urlTopicName = function(id) {
$.ajax({
url: 'ajaxStringScript.php',
type: 'POST',
data: {id:id},
success: function(data) {
console.log(data);
}
});
};
var f2 = document.getElementById('contentInput');
f2.value = urlTopicName;
}
</script>
Code: Select all
<?php
if (isset($_POST['id'])) {
deleteClient11($_POST['id']);
function deleteClient11($x) {
// your business logic
$stringURL = $x;
$stringURL = preg_replace('/[^\\pL0-9]+/u', '-', $stringURL);
$stringURL = trim($stringURL, "-");
$stringURL = iconv("utf-8", "us-ascii//TRANSLIT", $stringURL);
$stringURL = preg_replace('/[^-a-z0-9]+/i', '', $stringURL);
$stringURL = strtolower($stringURL);
return $stringURL;
}
}
?>