2012-11-21 11 views
5

Oto moja forma, wygląda poprawnie, więc to nie będzie problemem, usunąłem również entype, aby upewnić się, że to nie jest to.

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

Wewnątrz ControllerHello

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

Powroty "NULL"

Jakieś pomysły?

+0

jak na swoje pola wejściowego 'state' posiada zestawy do' wyświetlaczu: none', gdy forma złoży to wysłać wejście pusty do 'stanu', z tego powodu uzyskujesz' null' zamiast wartości. – Toretto

Odpowiedz

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

Następnie można użyć szeregu metod klasy JInput dla konkretnych celów:

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

Można spróbować zmienić swoje działanie formularz do:

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

Ponieważ zadanie nazywa się create nie hello.create może działać lepiej w ten sposób ....

Wtedy zawsze po prostu nie

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

'JRequest' jest przestarzałe od wersji Joomla 1.7. Nie, że się mylisz, ale lepiej jest użyć czegoś podobnego do następującego: '$ post = new JInput ($ _ POST);' dla Joomla 2.5 i nowsze;) – Lodder

+0

Poprawki Lodders. Zobacz tutaj, aby uzyskać więcej informacji na temat JInput http://docs.joomla.org/Retrieving_request_data_using_JInput –

8

Można spróbować -

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

Myślę, że najlepszym rozwiązaniem, aby dostać całą $ _POST z JInput jest

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

Jeśli chcesz uzyskać konkretną tablicę (o nazwie „jform "na przykład" z żądania, a następnie użyj

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

Możesz dostać Wartości z określonego Super Globalnego

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

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

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

Aby uzyskać więcej informacji, przejdź do Retrieving request data using JInput