Welcome Guest, Not a member yet? Register   Sign In
form_open newbie question about shortening code
#1

[eluser]Brad K Morse[/eluser]
I want to use form_open(); for posting to php_self

Code:
<?=form_open($_SERVER['PHP_SELF']);?>

renders html to:
Code:
<form action="http://domain.com/index.php/index.php/admin/update/4" method="post">

I know
Code:
<?=form_open('admin/update/'.$this->uri->segment(3));?>
will work, but there has to be a way the code can be shorter.

Any help is appreciated.
#2

[eluser]2think[/eluser]
Are you sure you fully grasp the concepts for Codeigniter's form handling and the Codeigniter MVC framework?

It would seem standard Codeigniter practice to point your form_open at a controller and method of that controller versus PHP_SELF.

If you want, you can still use the URI helper functions within that controller/method.

Here's the Form Helper in the User Guide: http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]Brad K Morse[/eluser]
I do not fully grasp the concepts of that.

Sounds like
Code:
<?=form_open('admin/update/'.$this->uri->segment(3));?>
is the only way.

Trying to keep it as clean/dynamic as possible.
#4

[eluser]Phil Sturgeon[/eluser]
Code:
<?php echo form_open(uri_string()); ?>

Only works if the URL helper is loaded.
#5

[eluser]Brad K Morse[/eluser]
Thanks Phil! That is what I was looking for. URL helper is loaded http://cl.ly/38689b7e7f6d633f3175
#6

[eluser]2think[/eluser]
Phil is pointing you to some housekeeping prior to using the Form Helper which are a must before using Helpers. Being one of the more knowledgeable and helpful users, he probably sensed that you may are tenuous on some of the concepts.

Seeing as you said you didn't fully grasp the Form Helper nor possibly the concepts of form_open & Codeigniter's MVC, perhaps you could invest some time going through the excellent Codeigniter User Guide.


I know there are a lot of people coming across to Codeigniter from sites that have offered lessons or tutorials and that is really excellent for the community as a whole in my opinion.

However, don't underestimate the "official guide" since it is part of what made Codeigniter such a fantastic platform.
#7

[eluser]Brad K Morse[/eluser]
http://ellislab.com/codeigniter/user-gui...elper.html is where I discovered form_open(), then I posted here to figure out a dynamic way to post to the current URL.




Theme © iAndrew 2016 - Forum software by © MyBB