2012-11-21 14 views
5

Ecco il mio modulo, sembra corretto, quindi questo non è un problema, ho anche rimosso l'enctype per essere sicuro che non fosse quello.

<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> 

All'interno ControllerHello

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

Returns "NULL"

Tutte le idee?

+0

Secondo il vostro campo di input di 'state' ha set a' visualizzazione: none', ogni volta che il modulo sottoporrà è inviare l'ingresso vuoto in 'state' questa è la ragione per cui si ottiene' null' invece di valore. – Toretto

risposta

4
$input = new JInput; 
$name = $input->get('name', '', 'post'); 
$country = $input->get('country', '', 'post'); 
// etc. 

quindi è possibile utilizzare una serie di metodi di classe JInput per scopi specifici:

// 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) 
-2

Si potrebbe provare a cambiare la vostra azione modulo per:

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

Dal momento che il vostro compito è chiamata non crea hello.create potrebbe funzionare meglio così ....

Poi ho sempre e solo fatto

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

'JRequest' è deprecato a partire da Joomla 1.7. Non che tu abbia torto, ma è meglio usare qualcosa come la seguente: '$ post = new JInput ($ _ POST);' per Joomla 2.5 in poi;) – Lodder

+0

Lodders correct. Vedi qui per maggiori informazioni su JInput http://docs.joomla.org/Retrieving_request_data_using_JInput –

8

Si può provare questo -

$input = JFactory::getApplication()->input; 
$post_array = $input->getArray($_POST); 
3

penso che l'opzione migliore per ottenere tutto il $ _POST con JInput è

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

Se si desidera ottenere matrice specifica ('jform 'per esempio) dalla richiesta, quindi utilizzare

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

È possibile ottenere Valori da una specifica Super globale

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

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

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

Per ulteriori informazioni, visitare il Retrieving request data using JInput