This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
URL rewrite
Started 14 years ago by mlykke | 5 posts |
-
Hi all
I couldn't find any posts about getting clean urls, like this www.mysite.com/myforms/apply/ instead of www.mysite.com/myforms/view.php?id=1.
I would like to add this functionality.
I plan on adding a db table called urls with fields form_id and url_segment and then adding php code that turns '/apply/' into 'id=1' and vice versa.
I think i will be able to add the insert statement when you create a new form but I'm a little unsure whether it's possible to somehow make the conversion in a separate file where I just put $input_array['form_id'] = 1, for example?
I know it's possible to make rewriting in server setup and .htaccess file but I would like to make this functionality dynamic. What are you're thoughts about this?
Thanks for an otherwise great app!
Posted 14 years ago # -
Let say you have machform installed under "myforms" folder. I suggest to create another folder called "forms".
Under "forms" folder, you can create an index.php file, which contains your form embed code, using the advanced form code, like this for example:
<?php require("/var/html/machform/machform.php"); $mf_param['form_id'] = (int) $_GET['form_id']; $mf_param['base_path'] = 'http://localhost/machform-test/'; display_machform($mf_param); ?>
As you can see, the "form_id" is being fetched from the GET parameter. This is where the rewrite need to do the job.
So, you can have an URL like this:
http://www.example.com/forms/23/my-form-title-here/and you only need to pass the id number (23 in this sample) to load the form properly, while the title is whatever you like.
MachForm Founder
Posted 14 years ago # -
I haven't test this yet, but you might be able doing it using this rewrite rule:
RewriteRule ^forms/([0-9]+)(.*)/(.*)$ forms/index.php?form_id=$1
MachForm Founder
Posted 14 years ago # -
Hi Yuniar,
I'm not really having any result with your first suggestion.
When I try to access http://www.example.com/forms/23/my-form-title-here/, I get a 404/Not Found - obviously because the directory isn't there.
Also, there must be a problem with accessing $_GET["form_id"], since there is no ?form_id=23 in the url?
And even if I add that parameter to the url, like http://www.example.com/forms/23/my-form-title-here/?form_id=23, I get mysql-query error Access denied for user 'SYSTEM'@'localhost' (using password: NO) [..] on line 18. User SYSTEM?? Where does that come from?
I'v been working with something like having a file called 'form' (no .php-extension) but with php-code in it. And then in my .htaccess file I have:
<FilesMatch "form"> ForceType application/x-httpd-php </FilesMatch>
...which will make Apache treat the file like a php file.
In the file form (without .php), I parse the url and set $_GET["form_id"] according to the url.
Then I can do http://www.example.com/form/1/test/ - except that this screws up css and js files paths... I'm currently working on a work-around (editing your code ;-))
I would like it to end up with http://www.example.com/form/test/ and then set the form id by querying the db for the id of the form named 'test'.
If I get it to work, I'll post the code (or email you it).
Your second suggestion might work but the url would still just be an integer and not the form title (which is what I would like it to be).
Thanks a lot for your help!
/Michael
Posted 14 years ago # -
I never took the time to work through the coding needed to implement my proposed suggestion and settled with the more handmade way of manually creating a subfolder for aech form with the form name and an index file inside it containing the advanced embed code as proposed by yuniar.
This topic can be closed, I think.
Posted 14 years ago #
Reply
You must log in to post.