Michael Samuel
Michael Samuel

Reputation: 3920

submit PHP form with get using slug

I have simple form:

<form action="/" method="get"> 

<select name="category">
<option value="social">social</option> 
<option value="tech">tech</option> 
</select>

</form>

If I choose tech and submit the form like this, i will get /?category=tech appended in the URL. Is it possible to get the SEO slug submitted instead. For example: /tech

Upvotes: 0

Views: 762

Answers (2)

Elangovan
Elangovan

Reputation: 3548

U can tying the below th link. Hi, u will try the .htaccess through the redirect the link
http://www.generateit.net/mod-rewrite/

Based on the slug functions we can crete seo friendly url.

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
       <label>Enter the Text :</label><input type="text" name="name"><br>
    <select name="category">
    <option value="social">social</option> 
    <option value="tech">tech</option> 
    </select><br>
       <input type="submit" name="submit" value="Submit Form"><br>
    </form>

<?php

function seo_friendly_url($string){
    $string = str_replace(array('[\', \']'), '', $string);
    $string = preg_replace('/\[.*\]/U', '', $string);
    $string = preg_replace('/&(amp;)?#?[a-z0-9]+;/i', '-', $string);
    $string = htmlentities($string, ENT_COMPAT, 'utf-8');
    $string = preg_replace('/&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '\\1', $string );
    $string = preg_replace(array('/[^a-z0-9]/i', '/[-]+/') , '-', $string);
    return strtolower(trim($string, '-'));
}
?>
<?php
if(isset($_POST['submit'])) 
{ 
     $name = $_POST['name'];
     $category = $_POST['category'];
    echo "<b>input value : </b>".$name;echo "<br>";
    $seofriendname = seo_friendly_url($name);
    echo "<b>SEO Function value</b> </br>".$seofriendname;
}
?>

Upvotes: 0

voldomazta
voldomazta

Reputation: 1340

You probably need some javascript on the onsubmit part of the form.

http://jsfiddle.net/qwa54/

Upvotes: 2

Related Questions