• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting to a view directory

#1
I am not sure that this is at all correct.

Under the sub_crud directory I have application, and under application I have controllers, models, and views )and config and some other stuff). Under views I have Users. Under Users I have a file called userAccount.php. 


In this case I am trying to submit to userAccount.php. It is getting called from:
<div class="regisFrm">
   <form action="userAccount.php" method="post">
       <input type="password" name="password" placeholder="PASSWORD" required="">
       <input type="password" name="confirm_password" placeholder="CONFIRM PASSWORD" required="">
       <div class="send-button">
           <input type="hidden" name="fp_code" value="<?php echo $_REQUEST['fp_code']; ?>"/>
           <input type="submit" name="resetSubmit" value="RESET PASSWORD">
       </div>
   </form>
</div>


Which causes this to show up in the browser address bar: https://www.rdsubstantiation.com/sub_cru...ccount.php
But I am getting a 404 error. I can see that the file is there. What am I doing wrong?
Reply

#2
The reference "userAccount" will be deemed relative to whereever the browser & apache think you are ... in this case a UserAccount controller (which btw won't map properly because of UCfirst) inside application/controllers/sub_crud/Users. Is this your intent?

If that is your intent, then you need to fix the filename case & link --> Useraccount.
If that is not your intent, then you need to provide an action link relative to your document root, e.g. /something/useraccount.

On the other hand, "sub_crud" is a folder containing the CI project? If you have the base_url set to "http://.../sub_crud", then "UserAccount" (which won't map properly) would refer to sub_crud/application/controllers/Users/Useraccount.

If this isn't the intent, then you need to provide some details about what you are expecting, and some of what your config looks like.
Reply

#3
(11-05-2018, 08:30 PM)ciadmin Wrote: The reference "userAccount" will be deemed relative to whereever the browser & apache think you are ... in this case a UserAccount controller (which btw won't map properly because of UCfirst) inside application/controllers/sub_crud/Users. Is this your intent?

If that is your intent, then you need to fix the filename case & link --> Useraccount.
If that is not your intent, then you need to provide an action link relative to your document root, e.g. /something/useraccount.

On the other hand, "sub_crud" is a folder containing the CI project? If you have the base_url set to "http://.../sub_crud", then "UserAccount" (which won't map properly) would refer to sub_crud/application/controllers/Users/Useraccount.

If this isn't the intent, then you need to provide some details about what you are expecting, and some of what your config looks like.

The problem is that there is both a Users.php in my controllers, and also a directory in views called Users. Perhaps the subdirectory should be lower case? In the views/Users directory I have a file called resetPassword. I guess I should call that one ResetPassword? 

What is happening is resetPassword is showing the form correctly.
Code:
<?php
/**
* Created by PhpStorm.
* User: richb201
* Date: 7/8/2018
* Time: 1:31 AM
*/

session_start();
$sessData = !empty($_SESSION['sessData'])?$_SESSION['sessData']:'';
if(!empty($sessData['status']['msg'])){
   $statusMsg = $sessData['status']['msg'];
   $statusMsgType = $sessData['status']['type'];
   unset($_SESSION['sessData']['status']);
}
?>
<h2>Reset Your Account Password</h2>
<?php echo !empty($statusMsg)?'<p class="'.$statusMsgType.'">'.$statusMsg.'</p>':''; ?>
<div class="container">
   <div class="regisFrm">
       <form action="userAccount.php" method="post">
           <input type="password" name="password" placeholder="PASSWORD" required="">
           <input type="password" name="confirm_password" placeholder="CONFIRM PASSWORD" required="">
           <div class="send-button">
               <input type="hidden" name="fp_code" value="<?php echo $_REQUEST['fp_code']; ?>"/>
               <input type="submit" name="resetSubmit" value="RESET PASSWORD">
           </div>
       </form>
   </div>
</div>

The submit seems to go to "https://www.rdsubstantiation.com/sub_crud/Users/userAccount.php", which is where I want it to go. Views/Users/userAccount.php exists, but the browser is reporting a 404 error.

What I'd really prefer to do to simplify this whole thing is to have the form above just pass the password and the fp_code into a function in my main controller Configure.php. Is there some way to pass the fp_code and the password into a function in my controller?
Reply

#4
>>The reference "userAccount" will be deemed relative to whereever the browser & apache think you are

In that case, how do I get back to my regular old controller directory?
I changed the form to:
<form name ="userinput" action="sub_crud/index.php/form_reader/save_userinput" method="post">
But now it goes to https://www.rdsubstantiation.com/sub_cru..._userinput

when I really want to run the function save_userinput() which is in sub_crud/Configure.php.
Reply

#5
Start your linked URLs with "/", which will restart at your document root as far as the browser is concerned, and with your normal routing as far as CI is concerned.
In other words, "/sub_crud/form_reader/user_input".
UNLESS your document root is mapped to "sub_crud/..."? in which case the form URL might have to be "/form_reader/userinput".
OR you could link to "/configure/processtheform" (your main controller).

Hard to tell what your configuration is (folders, web server mapping, base_url), etc, hence the vague advice.
Reply

#6
He is loading a view called Views/Users/userAccount.php

And in his form tag his action is using the same file name userAccount

Code:
<form action="userAccount.php" method="post">

The action should be pointing to the controller that is going to handle the form action.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
I have this in my routes

$route['default_controller'] = 'Users/login';
$route['subit_backend']['GET']='subit_backend/register';

Users is a controller. Configure is another controller. Subit_backend is another controller. I see the lower case in it. But it seems to work and I'd hate to break it.

I moved public function save_userinput() into Users. So now I have the form (which is in views/Users). This Users is a subdir of views.

<form name ="userinput" action="/Users/save_userinput" method="post"> This Users is a controller.

This is the function I put in the Users controller

public function save_userinput()
{
//code goes here
// for example: getting the post values of the form:
$form_data = $this->input->post();
// or just the username:
$username = $this->input->post("username");

// then do whatever you want with it Smile

}

When I run this I get in the address bar: https://www.rdsubstantiation.com/Users/save_userinput

and this int he window:
Not Found
The requested URL /Users/save_userinput was not found on this server.
Reply

#8
I really can't figure this out. Please help! I have reviewed the responses above. my form has:

<form name ="userinput" action="save_userinput" method="post">

which is bringing the browser to 

Code:
https://www.rdsubstantiation.com/sub_crud/Users/save_userinput

and throws a 404 error. 

Users.php is a controller that has a function called save_userinput(). 

I thought that in the CI world a function in controller Users would run.  Can I not use this CI construct with a form post?
Reply

#9
I have come to the conclusion (although I hope you guys can tell me how to fix it) when my form posts to
     <form name ="userinput" action="save_userinput" method="post">
The browser is trying to run a file called view/Users/save_userinput.php rather than the save_userinput method in the Users class. How can I get it to run the method instead of running the php file?

BTW, I also tried <form name ="userinput" action="account.php" method="post">

But that causes:


https://www.rdsubstantiation.com/sub_crud/Users/account.php

in the browser and that also gives a 404 error. Why a 404 error?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.