Yii routing on form action - php

I have a problem where, when submitting my form, it seems to ignore my routing and redirects me to the Home instead.
In my main.php routing:
'<language\w+>/profile/<slug:[\w\-]+>' => 'profile/index',
'<language\w+>/<action:\w+>' => 'site/index',
My form:
<form action="<?php echo Yii::app()->getBaseUrl()."/".Yii::app()->language;?>
/profile/calendar" method="post">
Which outputs to
<form action="/domainname/nl/profile/calendar" method="post">
Note: domainname is there because I'm testing this on localhost.
However, when pressing the submit button it forwards me to the home instead of the correct page. Simply visiting /domainname/nl/profile/calendar in the browser does work and gives me the correct controller. I don't know why it isn't working in the form.
In a different form on the same website, I have the following, which again does work fine for the routing:
<form action="/domainname/nl/profile/info" method="post">
The difference between these 2 forms is that the last one is created through CActiveForm widget and the first one isn't.

Make simple post request to "/domainname/nl/profile/info" and watch for response headers. Or you can analyze existing requests with tcpdump or something simular

I managed to work around the issue by switching my manual form to use the CActiveForm widget after all. It seems I needed the yii_cs_csrf_token that is automatically generated by CActiveForm.

Related

Submit button redirecting to different address

So the submit button of this form is supposed to send the data to localhost/mvc/contact/test and redirect to localhost/mvc/contact
at the first click of submit button it works well
Right
but when I click the submit button again its taking me to localhost/mvc/test
Not right
here is the html code of the form <form action="test" method="post" accept-charset="utf-8" class="contact">
when I had this as <form action="contact/test" method="post" accept-charset="utf-8" class="contact"> it first redirected me to localhost/mvc/contact but on second attempt redirected to localhost/mvc/contact/contact/test
Btw it's a simple mvc framework you may check it out on github for more clarity on Leggera # Github
The above mentioned code is present on view/contact/index.php
You can try these things:
You must give the full path to the file like <form action="contact/test/index.html" method="post" accept-charset="utf-8" class="contact">
In the index file of contact/test you can use <?php header("Location: http://www.example.com/");?> for redirection.
Maybe you have given wrong paths to files.
You must give more details for more specific answer

PhP form posts normally (data received on e-mail) but displays FORM.PHP PAGE NOT FOUND

Everything works well behind the scene but my clients see a Page not found after Posting a form.
The form.php must have been found otherwise the data wouldn't be parsed to my e-mail smoothly. I have a redirection page: thankpage.html, which is up and running well when I type its address directly.
what could be going on? any help please?
Anyway,
Instead of calling the Thankpage.html from the form.php, I inserted the following into my "form" element in the contact.html page itself:
onsubmit="window.location.href='http://www.inglesparticular-sp.com/thankpage.html';"
So it is now:
<form role="form" id="contact-form" method="post" action="form.php" onsubmit="window.location.href='http://www.inglesparticular-sp.com/thankpage.html';">
Somehow it's all working well and I have no "PAGE NOT FOUND" messages!!!
Sorry if I wasn't clear on the question, it's my first one as you can see... cheers!

Unknown php file path in a login form

When I saw the html code of login page a site, I saw the following url in part of the action feature.While when I learn about creating a form in internet, in the examples be used phpfilename with the .php and it is
incompatible with the tutorials that are in internet.
<form class="form-horizontal "
dir="rtl"
action="/login/?next=/account/?l=fa" method="post">
...........
..........
</form>
Its not always that the form action will be a .php, .asp or any server side side language. But this doesn't mean that the form is not processed by those server side languages, it's just that sometimes we rewrite the URL's in the .htaccess file, a file used to grant access to certain directories in webapps and also has the ability to redirect users from unknown or denied directories to usually the index page, to produce neat or let me say attractive URL's.
This is usually done in Single Page Applications (SPA) usually built with the MVC (Model View Controller) or MVVC (Model View ViewController).
The .htaccess provides the ability to write neat and attractive URL's. Behind the scenes it takes this so called neat URL and then explode it to find the .php or the server side language's file needed to process the form. This is usually called Controller in MVC apps.
As you are the very beginner in using php form so try to put the action field blank
<form class="form-horizontal" dir="rtl" action="" method="post">
Or something like this,
<form class="form-horizontal" dir="rtl" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
You are using post method to send data. So any of data not show in url.
So in your form action action="/login/?next=/account/?l=fa" you cnt use like this. Just give a page path like
action='login.php'
So in login.php, you can cathe the variables using $_POST.
$name = $_POST['name']//form input field name

File extension added after form submit

Let's say I have a form on my website homepage: www.mysite.com
Now, the form tag looks like this:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
</form>
When that form submits, it does everything it's suppose to. But it also reloads the page with the full filename and extension. So the user will now find the URL in the address bar is: www.mysite/index.php
Is there a way to make the form fire to the same page without adding this extension?
There may be situations where the form is as an include in a footer, so I cann't be specific about the page the form needs to fire to, hense the PHP_SELF code.
That's because $_SERVER['PHP_SELF'] refers to the actual filename of the current script.
Try this:
<form action="" method="post">
An empty action will post back to the current URL.
Try setting the action to #:
<form action="#" method="post">
...
</form>
The # refers to the current page.
Try changing action to #, this post to the current page.
Edit: Mike beat me to it.
Edit 2: It looks like you can leave out the action all together and it will default to the same page.
Edit 3: Mike beat me to that one too.

404 error when submitting form

I keep getting a 404 error when trying to submit this form. In my website directory i have a folder called mobile, which inside has forms.php and process.php.
The form is located on this page
http://localhost/mobile/forms.php?ft=0&id=2
here is the form
<form action='/mobile/process.php?o=9&ft=0' method='POST'>
//details
</form>
When i try to submit i get a 404 error, when it should go to http://localhost/mobile/process.php?o=9&ft=0? How do i fix this?
By looking at the URL's what I conclude is that both the php files are on the same page so change your action url from
<form action='/mobile/process.php?o=9&ft=0' method='POST'>
To
<form action='process.php?o=9&ft=0' method='POST'>
A forward slash before the mobile means it selects the folder from the root.. So you probably don't need that here.
Last but not the least, be sure the file names are proper, and also make sure the cases are same, because the file names are case sensitive.
Note: You may also get 404 error if you are using header('Location:
xyz.php'); on the form processing page, for redirecting the user to
some page after the form processes and you may encounter 404 because
the page on which the script has redirected doesn't exist. so make sure
that the URL is correct if you are using header()
Try changing
<form action='/mobile/process.php?o=9&ft=0' method='POST'>
to
<form action='process.php?o=9&ft=0' method='POST'>
Since they are in the same directory.
You can't pass a GET parameter in the form action.
In order to pass parameters, you will have to create a hidden input like :
<input type="hidden" name="o">

Categories