简体   繁体   中英

Getting $_POST with Joomla 2.5

Here is my form, it looks correct, so this shoulnd't be an issue , I also removed the enctype to make sure it wasn't that.

    <form action="<?php echo JRoute::_('index.php?option=com_woo&task=hello.create'); ?>" enctype="multipart/form-data" method="post">
      <p>
        Project Name : 
        <input style="width:30%;" name="name" id="name"/>
        <input style="display:none;" id="user_id" name="user_id" value="<?php echo $user->id;?>"/>
        <input style="display:none;" id="county" name="county"/>
        <input style="display:none;" id="state" name="state"  />
      </p>
      <button type="submit" class="btn-green" id="select_county">Create Project</button>
    </form>

Inside ControllerHello

    public function create()
    {
       $jinput = JFactory::getApplication()->input;
       $foo = $jinput->get('state', '', 'filter');
       print_r($foo);
       die;
    }

Returns "NULL"

Any ideas?

You can try this -

$input = JFactory::getApplication()->input;
$post_array = $input->getArray($_POST);
$input = new JInput;
$name = $input->get('name', '', 'post');
$country = $input->get('country', '', 'post');
// etc.

Then you can use a series of JInput class methods for specific purposes:

 // method      integer  getInt()       getInt($name, $default = null)    Get a signed integer.
 // method      integer  getUint()      getUint($name, $default = null)   Get an unsigned integer.
 // method      float    getFloat()     getFloat($name, $default = null)  Get a floating-point number.
 // method      boolean  getBool()      getBool($name, $default = null)   Get a boolean.
 // method      string   getWord()      getWord($name, $default = null)
 // method      string   getAlnum()     getAlnum($name, $default = null)
 // method      string   getCmd()       getCmd($name, $default = null)
 // method      string   getBase64()    getBase64($name, $default = null)
 // method      string   getString()    getString($name, $default = null)
 // method      string   getHtml()      getHtml($name, $default = null)
 // method      string   getPath()      getPath($name, $default = null)
 // method      string   getUsername()  getUsername($name, $default = null)

I think the best option to get entire $_POST with JInput is

JFactory::getApplication()->input->post->getArray();

If you want to get specific array (called 'jform' for example) from the request, then use

JFactory::getApplication()->input->get('jform', array(), 'ARRAY');

You can get Values from a Specific Super Global

$foo = $jinput->get->get('varname', 'default_value', 'filter');

$foo = $jinput->post->get('varname', 'default_value', 'filter');

$foo = $jinput->server->get('varname', 'default_value', 'filter');

For more information go to Retrieving request data using JInput

You could try changing your form action to:

<?php echo JRoute::_('index.php?option=com_woo&view=hello&task=create');

Since your task is called create not hello.create it might work better this way....

Then I always just did

$post = JRequest::get('post');
print_r($post['state']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM