I am porting an application to codeigniter developed in core PHP. By default query string functionality is disabled and I don't want to turn it on because I want the URLs to look clean. I have a page where there three forms: login form, registration form and forget password form. By default all the forms are collapsed. When the user opens this page from some other page by clicking on 'Login' button then login form should expand, and if the action of the user was "Register" button then registration from should exapnd when page is loaded. The earlier developer has appended action attribute to button links and added "login" and "register" values to them. This helps him to retrieve whether request was for login or register and he expands the collapsed form accordingly. But since codeignter URLs don't work this way how do I remember the user action when login or register button is clicked?
I am sorry if I could not write it clearly what I am trying to ask, if further information is needed I can edit and write more.
Thanks!
When in controller save the action in a variable:
$data = array();
$data['action'] = $this->input->post('submit'); #retrieve the action depending on the submit name
$this->load->view('view', $data);
Now, you will get the $action in the view and show the form depending upon it. Hope it helps you.
Related
My index page starts with login form, underneath the "Log in" button there's a sign up message for those who have not made the account yet. I made both registration and login form inside one div and used javascript to toggle between them when clicking anchor tag (either "Log in" or "Sign up"). I've made a login system already but Im having issues with registration and it's validation. Since both forms are on the same page and default one is login one there is a problem with validation because when you're trying to register a and you provide a username that's too short the page reloads and you're back to login form, then need to click "Sign up" again to toggle between the forms and there's the validation error. Is there anyway I can somehow stop the page from reloading or making it so the website remember that you were at registration form?
I hope I explained my issue good enough, english is not my native language...
I can provide any code needed.
Well I guess the other way to prevent that from happening would be swapping forms and making registration form the default one but is there an answer to my question?
I would use a query string on the url. https://codepen.io/adrianparr/pen/XJEbQW
You might have to add it to the url when they click sign up. Then on page load you can check if the query string is there and animate to the registration form instead of the login form. I'd use a query string like.... ?signup=true
So,
User clicks sign-up -> animate form and add to url
The page reloads for some reason...
Check on page load for query string value of "signup=true" or just "signup" and animate to the sign up form.
Note: So really your goal is to check for a value on pageload, or you could even use a hashtag, cookies, or local storage technically. The point is that on click you are setting a value somewhere, and on pageload you are checking for that value. And of course, after the user finished what you want them to you need to clear the value.
I have got a form in which I want to show html links. To avoid that a user looses form inputs in case clicking the link, I want to inform the user before he leaves the form.
To achieve that, I tried
public function registerAction(Registration $registration = null) {
$formHasBeenSubmitted = !is_null($registration);
$this->view->assign('formHasBeenSubmitted', $formHasBeenSubmitted);
}
But it is always false.
What is the correct way to find out if the form for a specific action has been submitted?
Update after undkos answer:
I would like to show the message in case the form has been submitted but validation errors have been showing up and of course also as soon as the user started entering data.
Behind a link there is a form which edits data (postal addresses) which are shown on the main form and should be updated there after editing.
As a user I don‘t care if the form has been submitted or "just" filled in - hence I suggest to create a modal whenever there‘s data in your form.
Another possibility of improving usability is to create links with target attribute. Both, modal and target, impose their own issues so it‘s always a trade-off.
i have a login system in my CI application, so i follow this tutorial : click here!
But when i send my data using button login it redirect me to 'home/verifylogin' instead 'verifylogin'.
check the value you have put in the 'action' attribute in form tag in view page. If you want to call 'verifylogin' controller then marked at there.
I'm developing an application in mobile view using CakePHP, where there's no Javascript code can run.
My scenario:
In user login form, users clicked submit button. But before the data submitted and users go to the next page, I make an 'interruption' page (renders a new view). In there, contains "Facebook" and "No, thanks" button. When they click "Facebook", they will connect their Facebook accounts. But, if they click "No, thanks", the login continue.
My question is, how can I make that "No, thanks" button? Because if I use <input type="submit"> button, the form that contain its data is in previous page, so this button will not be clicked. And, how to store POST data, and when that "No thanks" button clicked, then, the data submitted?
You can either store the data in session, or you can make the "no thanks" button the submit button of a form where all the data from the previous page is stored in hidden form fields.
Personally for a number of reasons, I would prefer to utilize sessions, but since you are even asking this question, I am guessing you are unfamiliar with usage of session data.
A simpler question would be:
To make these two forms on single page but with LOTS of vertical or horizontal space in between user login form & 'interruption' page so user seeing the login form can't see interruption section although both are within same <form></form> tag. Then, the the submit button is simply a link to interruption section of the same form. this link is simple an <a> tag with inline linking, which would hide the login form & display interruption page without needing javascript. similar to links to Go to Test Section A on this page
http://www.dynamicdrive.com/dynamicindex5/bookmarkscroll.htm
Further then in the interruption section you can use a real submit button which makes a POST back to request the server.
[edit]
This workaround is based on assumption that user doesn't scroll far enough. Because most users won't, making it 1step process for them instead of 2process which is specially important on mobile. And if somebody does then the empty form gets submitted to the server & then we can run validation & return a error to the user. where he/she can fill the complete form. so This is a good workaround better than storing the data in session & making two POST request for every user login over mobile network which are generally unreliable.
A better solution might be just to combine both forms into one form. Then you don't have to make 2 http requests. Maybe all you need to do is to add one extra button to the original form "Login with FaceBook" next to the other submit button.
I want to create a layout with a login form.
Where should i write the controller code for that login form? In every actions where the layout is shown? (I dont think so..) Is there any specific controller part related to the layout?
You should simply create a specific action where you'll handle the login form submissions, create a route for it, and point the login form to that route.
Then in that action you can make use of Symfony\Component\HttpFoundation\RedirectResponse and after the successful login redirect the user back where he came from. From the outside it won't be noticeable, that the user is going to another page, and you don't have to put the code to every action using the layout.