i'm new in coding joomla components i'm coding my first component at all and starting my knowledge from 0 in PHP
in my component i have 4 file uploaders (3 for images/pdf/etc.. and 1 for videos) and i would like to add a button to remove the file in case the person doesn't want the file anymore
can help me in this ?
here's the code of the form page:
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('video'); ?></div>
<div class="controls"><?php echo $this->form->getInput('video'); ?></div>
</div>
<?php if (!empty($this->item->video)) : ?>
[View File]
<?php endif; ?>
<input type="hidden" name="jform[video]" id="jform_video_hidden" value="<?php echo $this->item->video ?>" /> <input type="hidden" name="jform[ordering]" value="<?php echo $this->item->ordering; ?>" />
<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
<input type="hidden" name="jform[checked_out]" value="<?php echo $this->item->checked_out; ?>" />
<input type="hidden" name="jform[checked_out_time]" value="<?php echo $this->item->checked_out_time; ?>" />
Any further information you need ask and i'll provide it
In your controller file, you should add a function called deleteImage that will delete the image from the filesystem. In your layout file (your view's template, as in "default.php"), you should add a link next to each uploaded file that goes like this:
index.php?option=com_pressrelease&task=deleteImage&id=imageId
Related
I'm trying to get a login form that has been called by a CMS page to work but when tested, it redirects back to the page and doesn't log the user in.
I guess this is to do with not having the right form key as I notice the default login page has the URL format,
www.mydomain.com/customer/account/login/referer/blahblahblah/
and the form calls the function, getPostActionUrl() which generates this URL for the form action,
www.mydomain.com/customer/account/loginPost/referer/blahblahblah/
So how do I get my form to use that blahblahblah key?
The form does generate a hidden input called form_key. This isn't the same as blahblahblah though.
Here is the code of the form. Can anyone suggest how to get the blahblahblah key and where to drop it in the form code?
<div class="block block-login">
<div class="block-title">
<strong><span><?php echo $this->__('Login') ?></span></strong>
</div>
<?php echo $this->getChildHtml('customer.form.login.extra')?>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<?php echo $this->getBlockHtml('formkey'); ?>
<div class="block-content">
<label for="mini-login"><?php echo $this->__('Email:') ?></label>
<input type="text" name="login[username]" value="<?php echo $this->escapeHtml($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Email Address')) ?>" />
<label for="mini-password"><?php echo $this->__('Password:') ?></label>
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Password')) ?>" />
<div class="actions">
<button type="submit" class="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Login')) ?>" name="send" id="send2"><span><span><?php echo $this->__('Login') ?></span></span></button>
</div>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
//]]>
Got this to work with a bit of research.
First of all, I found this thread: Magento adding referer param to getLoginPostUrl()
That gave me the basis for a partially successful solution.
First off, in
app/design/frontend/base/default/template/cms/cmslogin.phtml
(a custom file I created for this login form)
I replaced,
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
with,
<?php $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
echo Mage::helper('core')->urlDecode($referer);
?>
<form action="<?php echo Mage::getUrl('customer/account/loginPost', array('referer' => $referer)); ?>" method="post" id="login-form">
It seems that was all that was needed to get the login form working.
The problem I have now is that, despite "Configuration > Customers > Customer Configuration > Login Options > Redirect Customer to Account Dashboard after Logging in" being set to NO, the form is redirecting to the Dashboard - I want it to redirect back to the CMS page (which when the user is logged in and a member of a particular customer group, shows different content). Will ask this separately.
This is a hopeful question. I am really, really PHP inexperienced. But I am trying to teach myself a thing or two. The organization I work for uses a WP site. I regularly work on it. I mostly do HTML and CSS (stuff I know about) but I was just digging around in the background and came across something I don't understand at all.
I made a test page here: http://all4ed.org/webinar-event/test-2/
There are two forms on the page. The first ends in a "submit button," the second ends in a "Register Button."
So far so good. I dug around the backend of the WP files, and found the content-webinar.php file and saw that it pulled the form in as an include with:
// The registration form. ?>
<?php if ($registration_required == 'yes'): ?>
<?php include ('assets/includes/webinar/inc-block-registration-form.php'); ?>
<?php endif;
Good, so far.
I went to the "inc-block-registration-form.php" file and here's where it gets weird:
The first form is done with this code:
<form class="webinar-registration" action="<?= $_SERVER["REQUEST_URI"] ?>" method="get">
<div>
<p>
<label for="token">Token</label>
<input type="text" name="token" />
</p>
<p>
<button>Submit</button>
</p>
</div>
</form>
This looks exactly like I thought it would. The second form is written like this:
<form class="webinar-registration" action="<?= $_SERVER["REQUEST_URI"] ?>" method="post">
<div>
<?php if ($webinars->error) : ?>
<p class="error"><?= $webinars->error ?></p>
<?php endif; ?>
<?php foreach ($webinars->form_data as $data) : ?>
<p><?= $webinars->build($data) ?></p>
<?php endforeach; ?>
<p>
<button>Register</button>
<input type="hidden" name="webinars_registration_submitted" value="<?= $post->ID ?>" />
<input type="hidden" name="webinars_registration_title" value="<?= get_the_title() ?>" />
<input type="hidden" name="webinars_registration_url" value="<?= get_permalink() ?>" />
<!-- fields necessary for AA -->
<input type="hidden" name="webinars_user_id" value="<?= get_current_user_id() ?>" />
<input type="hidden" name="webinars_type" value="<?= get_field('webinar_type') ?>" />
<input type="hidden" name="webinars_post_id" value="<?= get_the_ID () ?>" />
</p>
</div>
</form>
Huh???? Where is the "Your Name", "Your E-mmail Address," "Organization," "City, State," or "Question (This is optional)"
How does this work? Where is it pulling those fields from. Any insight would be appreciated. Thanks.
If the above title looks confusing then here is the description....
I have a template page where I have placed the wordpress default registration form. Now what exactly I want is to add few extra fields on that form.
The wordpress registration will go on as it is. I mean the username and email and password gets stored on the database but along with that new fields or extra details like phone/address/age etc etc gets emailed to a specific email id.
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<div class="username">
<label for="user_login"><?php _e('Username'); ?>: </label>
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" tabindex="101" />
</div>
<div class="password">
<label for="user_email"><?php _e('Your Email'); ?>: </label>
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" tabindex="102" />
</div>
<div class="login_fields">
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="<?php _e('Sign up!'); ?>" class="user-submit" tabindex="103" />
<?php $register = $_GET['register']; if($register == true) { echo '<p>Check your email for the password!</p>'; } ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</form>
**Note:- The new fields aren't added here.
Is it possible? If yes, then how? Should I add a second form below this form which fires the email? Kindly please suggest an appropriate solution for this.
I have already created a custom layout for my Magento theme which works fine. The only issue I have so far is that my registration does absolutely nothing. I have tried searching but only seem to come up with results on how to add new fields to a registration page. My current code is as follows:
<div id="user-login">
<span class="log-head loginfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<h2>You Already Have An Account</h2>
<p>Please login with your e-mail and password</p>
<span>
<label>Enter your E-mail address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
</span>
<input class="submit" type="submit" value="Submit">
</form>
</span>
<span class="log-head registerfield">
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
<input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
<input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
<h2>You Don't Have An Account</h2>
<p>Please enter your information and create an account</p>
<span>
<label>Email Address:</label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</span>
<span>
<label>Enter your password:</label>
<input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
</span>
<span>
<label>Re-Enter your password:</label>
<input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
</span>
<input class="submit" type="submit" value="Create Account">
</form>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
<?php if($this->getShowAddressFields()): ?>
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
<?php endif; ?>
//]]>
</script>
</span>
</div><!--/user-login -->
I combined the registration and login page to fit my design. The input fields are taken directly from the base theme. After I try to test and create a user the page just refreshes and the user is never created. The same goes if I create a user from the backend and try to login the page refreshes but never logs me in.
Any help will definitely be appreciated.
The reason you are have issue is because both forms are pointing to the same form action (assuming that the input names are the same as default magento)
action="<?php echo $this->getPostActionUrl()
This should Fix your issue
Change this (I not sure which block type you are using so i'm going to change both action)
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
to
<form action="<?php echo Mage::helper('customer')->getLoginPostUrl() ?>" method="post" id="login-form">
Change this
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
to
<form action="<?php echo Mage::helper('customer')->getRegisterPostUrl() ?>" method="post" id="form-validate">
If this doesn't work then view page source and look where both form action is pointed (see below for location where they should point). Try changing the action to
<?php echo Mage::getUrl() . '/customer/account/loginPost/'; ?> and <?php echo Mage::getUrl() . /customer/account/createpost/ ?>
Reason for Issue
By default magento sperate the registration and login form into 2 different pages which uses two different block
see /app/design/frontend/default/contempospace/layout/customer.xml (customer_account_create and customer_account_login)
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
Both block have a method getPostActionUrl() which point to different url /customer/account/loginPost/ and /customer/account/createpost/
See
/app/code/core/Mage/Customer/Block/Form/Login.php
/app/code/core/Mage/Customer/Block/Form/Register.php
You may want take a look at How Blocks And PHTML Work Together
Try to use:
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
And you should use the same name to field from origin's one.
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
<block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml">
Everyone was super helpful with this ( I had the same problem ). Took me a bit, but this surfaced after a recent upgrade. The issue was that the registration form didn't have the formkey field in it, simply add the line below to the form and it started working properly for me.
<?php echo $this->getBlockHtml('formkey')?>
So I have a bunch of divs that are hidden on load unless a checkbox is ticked.
It works on the change event, but on the refresh of the page the divs return hidden unless you turn the checkbox off and then back on.
I was wondering if there is a way to check which checkbox is ticked on load and then display:block, rather than ticking and unticking.
HTML/PHP
<div class="misc-pub-section">
<label><b>Year of release</b></label>
<input name="review_release_year" value="<?php echo $review_release_year; ?>" />
</div>
<div class="misc-pub-section">
<label><b>Director/Author/Company/Developer</b></label>
<input name="review_owner" value="<?php echo $review_owner; ?>" />
</div>
<div class="misc-pub-section">
<label><b>Generic Website Link</b></label>
<input name="review_website_link" value="<?php echo $review_website_link; ?>" />
</div>
<div class="misc-pub-section feature-short-webseries" style="display:none;">
<label><b>IMDb Title Link</b></label><br/>
<em style="color: #999;">imdb.com/title/</em><input size="9" name="review_imdb_link" value="<?php echo $review_imdb_link; ?>" />
</div>
<div class="misc-pub-section feature-short-webseries" style="display:none;">
<label><b>Story rating (out of 5)</b></label>
<input max="5" name="review_story_rating" value="<?php echo $review_story_rating; ?>" />
</div>
<div class="misc-pub-section feature-short-webseries-videogame" style="display:none;">
<label><b>Enjoyment rating (out of 5)</b></label>
<input max="5" name="review_enjoy_rating" value="<?php echo $review_enjoy_rating; ?>" />
</div>
<div class="misc-pub-section feature-short" style="display:none;">
<label><b>Soundtrack rating (out of 5)</b></label>
<input max="5" name="review_sound_rating" value="<?php echo $review_sound_rating; ?>" />
</div>
<div class="misc-pub-section webseries" style="display:none;">
<label><b>Attention span rating (out of 5)</b></label>
<input max="5" name="review_span_rating" value="<?php echo $review_span_rating; ?>" />
</div>
<div class="misc-pub-section hardware-software" style="display:none;">
<label><b>Features rating (out of 5)</b></label>
<input max="5" name="review_features_rating" value="<?php echo $review_features_rating; ?>" />
</div>
<div class="misc-pub-section hardware-software" style="display:none;">
<label><b>Function rating (out of 5)</b></label>
<input max="5" name="review_function_rating" value="<?php echo $review_function_rating; ?>" />
</div>
<div class="misc-pub-section hardware-software" style="display:none;">
<label><b>Value rating (out of 5)</b></label>
<input max="5" name="review_value_rating" value="<?php echo $review_value_rating; ?>" />
</div>
<div class="misc-pub-section software" style="display:none;">
<label><b>Operating System</b></label>
<input name="review_system_rating" value="<?php echo $review_system_rating; ?>" />
</div>
<div class="misc-pub-section videogame" style="display:none;">
<label><b>Graphics rating (out of 5)</b></label>
<input max="5" name="review_graphics_rating" value="<?php echo $review_graphics_rating; ?>" />
</div>
<div class="misc-pub-section videogame" style="display:none;">
<label><b>Gameplay rating (out of 5)</b></label>
<input max="5" name="review_gameplay_rating" value="<?php echo $review_gameplay_rating; ?>" />
</div>
jQuery
$(function() {
var a = $("#in-review-type-14"), b = $("#in-review-type-67"), f = $("#in-review-type-68"), d = $("#in-review-type-69"), e = $("#in-review-type-70"), c = $("#in-review-type-71"), h = $("#review-typechecklist input");
$(h).change(function() {
a.is(":checked") || b.is(":checked") || c.is(":checked") ? $(".feature-short-webseries").show() : $(".feature-short-webseries").hide();
a.is(":checked") || b.is(":checked") || c.is(":checked") || e.is(":checked") ? $(".feature-short-webseries-videogame").show() : $(".feature-short-webseries-videogame").hide();
a.is(":checked") || b.is(":checked") ? $(".feature-short").show() : $(".feature-short").hide();
c.is(":checked") ? $(".webseries").show() : $(".webseries").hide();
f.is(":checked") || d.is(":checked") ? $(".hardware-software").show() : $(".hardware-software").hide();
d.is(":checked") ? $(".software").show() : $(".software").hide();
e.is(":checked") ? $(".videogame").show() : $(".videogame").hide()
})
});
If the logic for the change event handler function already works correctly all you need to do is trigger that event handler when the page loads (after it has been bound):
$(h).change(function() {
...
}).trigger('change');
On an unrelated note, ternary operators are generally used for storing or passing values based on a condition, rather than branching execution (that's what an if statement is for). Your code will work, you'll just get errors if you run it through a tool such as JSLint it will complain about it.
You need to create cookie for every check box option.
For example if you check one option and DIV is visible now, then create cookie for that DIV call it something related to that DIV and set it's content to something that will associate yo that it is ON like true.
Then when reloading page check in php if that cookie exists and it's content = true and if that set style display to block of that particular DIV.
For turning off visibility you can either set cookie time to -x seconds to make it expired or update cookie content to false.
You can make cookie with javascript on same page on which you click those checkbox-es no need for reloading.
Every loading of the page erases the DOM so you must save temps data in cookies.