In joomla 1.7 i am creating a custom module for registration. How I can check the user field
is empty or not? Which function is used to check user input field like isset() which is used
in php.
I want to check for form is submitted or not in joomla, according to that i want to display information.
You can use $_POST && $_GET
or
use the functions of jommla framework (recommended)
JRequest::getString('INPUT_NAME','DEFAYLT_VALUE')
check this link :
http://docs.joomla.org/JRequest/1.6
so to check use :
$Name = JRequest::getString('name_field',false);
if(false){
//NOT SET
}else{
//ISSET
}
Related
How can I pass default value in resource field without showing that field in form while creating and updating?
I know I can use withMeta(['value' => '1']) to pass default value but it will won't work if field is not visible on form.
also, I know that in the model I can use $attribute variable to pass default value but I only want to pass the default value if resource created is from nova.
I've had good success with a combination of these two packages:
https://github.com/inspheric/nova-defaultable-fields
https://github.com/MohmmedAshraf/nova-hidden-field
For example:
Text::make('Email From')
->default(env('MAIL_FROM_ADDRESS')),
and
HiddenField::make('created_by_id')
->hideFromDetail()
->hideFromIndex()
->default(Auth::user()->id),
I noticed that in the older laravel blade template it was recommended to use old (key, value) to retrieve old values when form validation fails. (controller method handling the validation will post back to the form with the as-is data in request object)
Is it still necessary to use it in the latest laravel version ?
When should one use the old (key, value) function on the form fields on laravel blade template?
In Laravel there is a convention that most "get me some value" like functions provide a way to cover case "there is no value to get", therefore signature of most getter like functions looks like:
get('key', $default = null)
So in your case you would want to use old('key', default) in:
create form when you as programmer set valid default value (not placeholder), perhaps date of some action for "today/now" old('publish_at', Carbon::now()).
edit form old('publish_at', $post->publish_at), which means that on first load of edit form input field is pre-populated with data from database
I have some trouble figuring out how to do this properly.
I have Users that can create Articles which can be viewed, edited and deleted. I want to restrict the edit and delete actions if the currently logged in user is not the creator of the Article.
I have already done this using Policies and use Gate within a Form Request, but if i understand correctly FormRequest is only for POST requests. And I currently pass the FormRequest as a parameter to the getEdit() action. That seems wrong.
So how can I make sure the user can neither access nor edit the Article?
If you already defined a Policy you can directly access it using the Gate facade within your controller action like this:
public function getEdit($id)
{
$reference = Reference::findOrFail($id);
if (Gate::denies('owns-reference', $reference))
abort(403);
return view('reference.edit')
->with('reference', $reference);
}
Just make sure to include the Gate on top of your file like this:
use Gate;
I'm pretty new to PHP programming and Magento. I wanna to pass the current ProductId from a form within a custom block to a controller (new action).
Yes I know that one method would be to add an input hidden (with my product id) in the custom block form and then to retrieve the Value through a regular:
$this->getRequest()->getPost('myvalue'))
Is there a better way in Magento to retrieve the value within the controller without having to declare extra secret input fields ?
Good for you for wanting to adhere to best practices within Magento! The passing of data to controllers is pretty standard, however. If we look at how the product is added from a product page, we'll actually see the product ID in the form action URL's parameters:
http://domain.com/checkout/cart/add/uenc/uenc_value/product/45573/
...where 45573 is the product ID. Of course this can also be sent to the controller via a hidden input field, which I use all the time. Note that the above is the same as http://domain.com/checkout/cart/add/?uenc=uenc_value&product=45573 in Magento.
Another way of storing data for use in controllers for future use is setting data into a session. For posting data to a controller I wouldn't recommend this method but it's something to keep in mind:
$session = Mage::getSingleton('core/session');
$session->setMyValue(true);
We can then retrieve the data from my_value later just by instantiating the session. Good luck!
Passing your data could be done in different ways :
You could use Magento's magic setters and getters.
So you would have to do this to set the value :
Mage::getSingleton('core/session')->setSomeVariable($value);
and this to retrieve it :
Mage::getSingleton('core/session')->getSomeVariable();
Or you could use the register.
Mage::register('key', $value); //to set your data
Mage::registry('key'); //to get your data
Magento provides a way to construct a URL with the necessary values, calculated against the configuration DOM. Blocks (and therefore block templates) can call Mage_Core_Block_Abstract::getUrl() directly:
$this->getUrl('some_handle/foo/test',array('id'=>'some_value'));
// Mage::getUrl() will work as well
The above would result in the following URL:
http://base_url/frontname/foo/action/id/some_value/
...which can be read in the FooController testAction() as
$this->getRequest()->getParam('id') // 'some_value'
The form validation library seems to only work on POST. I need to use query strings and would like to use CI to validate the passed values. Is there a way to do this?
The current Codeigniter 3.0 development branch provides an option to insert your own variable instead of $_POST. So you could start using 3.0.
Alternatively, the only way in CI2.1 is to do $_POST=$_GET before you run the validation.
See this page for the CodeIgniter 3 solution:-
http://www.codeigniter.com/userguide3/libraries/form_validation.html#validating-an-array-other-than-post
For CodeIgniter 2 you can do $_POST = $_GET; before $this->form_validation->run() as mentioned above.
You could overwrite the Form_validation function run in a MY_Form_Validation and modify it.
Reference How do I validate a form field in Codeigniter when using Get parameters?
Before validation rules, set the validation data with the following code.
$this->form_validation->set_data($_GET);