Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
newbie, how to get $_POST or $_GET
  • hi all, im beginner in fuelphp,
    i have problem in basic one,

    this my html:
    <?php
        echo Form::open('input/company/getData');
        echo Form::input('name');
        echo Form::submit();
        echo Form::close();
    ?>

    i write this code in my controller to get param by POST method,
    function action_getData()
    {
         $name=Input::post('name');
        echo $name;
    }

    the name i input from html not display.
    am i wrong write the code, please correct me friends.
    thanks b4.
  • ilNotturnoilNotturno
    Accepted Answer
    Can you post your routing and your entire controller head (name and which class it extends)?
  • i extends just Controller, not use template, rest or hybrid

    this is my route.php:
    '_root_'  => 'main/index',
        '_404_'   => 'main/404',

    this is my config.php:

    return array(
        'base_url'=>'http://siarp/',
        'url_suffix'=>'.html',
        'index_file'=>'index.php',
        'language'=>'en',
        'security.csrf_autoload'=>TRUE,
        'security.csrf_token_key'=>'siarp12345',
        'security.csrf_expiration'=>200,
        'security.url_filter'=>array('htmlentities'),
        'security.input_filter'=>array('$_GET','$_POST','$_COOKIE'),
        'security.auto_filter_output'=>TRUE
    );

    im new in fuel,
    is both of my file correct ??
  • Your array structure is not correct.

    'security.csrf_autoload' should be 'security' => array('csrf_autoload' => ...)

    dot-notation is the way array access is documented in Fuel (as a short way to define a complex multidimensional array), and support by the Arr class.

    Check the fuel/core/config/config.php file, which contains the correct structure and all default values.

    And

    'security.input_filter'=>array('$_GET','$_POST','$_COOKIE'),

    is definitely not correct. This should be a list of input pretreater methods, like 'htmlentities' is defined for the url_filter.

    The standard practice is not to filter on input (as it will potentionally alter the input values), but encode on output (which is activated by default), so by default the input filter in an empty array.
  • thanks so much Harro Verton for the comment, really useful.

    my config.php is located in fuel/app/config/, not in /core/config/. i do so, bcoz i follow what is in fuel documentation, or may be im wrong,
    but, btw, what's different between config.php in app/config/ folder and core/config/ folder??

    bcoz in CI, i just edit 1 config.php file in application/config/config.php,

    thanks b4...
  • You're config should indeed be in app/config.

    But for every config file, there's one in fuel/core/config that contains all default values. When the config is loaded, both are loaded and merged so you only have to specify the changes in the app file.

    Fuel works this way so that when you upgrade to a newer version, you don't have to go changing stuff in your application.

    Which in CI you have to do when they introduce something new (which they haven't done in donkeys years, but that's another story).
  • Harro Verton, thanks alot,
    but i still cant display my data using Input::post('name'); just like what i said above,
    can you help me?

    here is my config.php:
    return array(
        'base_url'=>'http://siarp/',
        'url_suffix'=>'.html',
        'index_file'=>'index.php',
        'language'=>'en',
        'security'=>array(
            'csrf_autoload'        => TRUE,
            'csrf_token_key'       => 'csrfToken',
            'csrf_expiration'      => 300,
            'uri_filter'        => array('htmlentities'),
        ),
        'htmlentities_flags'    => ENT_QUOTES
    );

    n one more thing, when i comment or delete the array config, it works!
    but why's like that?? is there wrong in my config again??
  • 'htmlentities_flags'    => ENT_QUOTES

    should be inside the security array, but that shouldn't make a difference.

    Perhaps a csrf violation? Can you set csrf_autoload to false?
  • okay Harro Verton, but it still don't display my data,
    i dont know where is my wrong located.

    now, i've just copy all the default config in
    /core/config n paste them in app/config, n it works,

    but, there' one thing i confuse about, after i copy paste the config array,
    in 'index_file' section, it said, if i dont use URL rewriting, just give it 'index.php',
    so i change become 'index_file' => 'index.php',
    n try to input my data again n i doesn't work,

    but when i left 'index_file' default it works.
  • The 'index_file' configuration key is only relevant for the generation of URI's using the Uri::create() method, it isn't used elsewhere.

    In your original post, you used

    echo Form::open('input/company/getData');

    which will use Uri::create() to create the form's action URL. It will use both the base_url from your config and the defined index file to generate this URL.

    If this generates an incorrect URL, you will get a 404 when you try to submit the form. It the submit of the form correctly loads the getData method, then the URL was ok, and so was your config.

    So perhaps it's time you say exactly what "doesn't work" means to you, what exactly happens...
  • I've tried to do what you've provided here and it work fine.

    So, what do you mean it doesn't work?
    Showing 404 Page not found? the input value cannot display? or what?

    Since you don't have much info in route.php, so, have you created a folder 'input' in app/classes/controller and a file 'company.php' in the input folder?

    Do you name the class as:
    class Controller_Input_Company extends Controller 

    Please explain more details on what doesn't work.
  • thanks so much all for the answer :)

    i dont know exactly the error, but i reinstall my app with the new fuelphp master file,
    n i try it again, the config file, just like Harro Verton said, n it work well!
    hm.. may be i missing some in unknown file. :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion