Is it possible to have two actions fire on a form? - php

I understand you can't have two form elements. Here is my code below:
<form method="post" action="http://enews.thewebsite.com/q/Z_-p5ayQihZRLi2J67qUQ1aYrMDxK9jLRT" accept-charset="UTF-8">
<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-validate-detail<?php echo $this->getAdditionalFormId(); ?>">
<input type="hidden" name="crvs" value="hj8DUzs3ID-3PTnoCEYQBZnP-ywiXCvSIopgDNLjkjI8uXaXEdhIDPteMAiIyBcEx_IEuTzvEtyZyY_6wp6uKKp5ljddRi7lbgSnjg9EM_tdAFCK1mCGHA7rrAZ8_zyk1GjuYtSzOIe60HJ-s5oV9doy1naJOZ-afDbkKAOxuVw"/>
<div class="form-subscribe">
<div class="form-subscribe-header">
<label for="newsletter"><?php echo $this->__('Sign Up to Receive Our Newsletters') ?></label>
</div>
<div class="form-subscribe-input"><input name="email" type="text" id="newsletter" value="<?php echo $this->__('Email Address') ?>" onclick="this.value=='<?php echo $this->__('Email Address') ?>'?this.value='':''" onblur="this.value==''?this.value='<?php echo $this->__('Email Address') ?>':''" class="input-text required-entry validate-email" /></div>
<div class="form-subscribe-submit"><button type="submit" class="button" title="<?php echo $this->__('Sign Up') ?>"><span><?php echo $this->__('Sign Up') ?></span></button></div>
</div>
</form></form>
<script type="text/javascript">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail<?php echo $this->getAdditionalFormId(); ?>');
//]]>
</script>
The first post action is the one that is taking precedence. I would like them both to fire in the order they are now.
Is this possible?
Perhaps i can use some javascript like so:
<script type="text/javascript">
function doPreview()
{
form=document.getElementById('newsletter-validate-detail');
form.target='_blank';
form.action='thewebsite'; //first action
form.submit();
form.action='backto-other-action'; //second action???
form.target='';
}
</script>

Related

magento newsletter subscription not working in magento 1.9.2.2

newsletter subscription not working in all pages. no newsletter confirmation mail send to customers
<div class="custom-subscribe">
<div class="title">
<span><?php echo $this->__('Newsletter') ?></span>
</div>
<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-validate-detail">
<div class="form-subscribe-header">
<label for="newsletter"><?php echo $this->__('Sign Up for Our Newsletter:') ?></label>
</div>
<div class="input-box">
<input type="text" name="email" id="newsletter" title="<?php echo $this->__('Sign up for our newsletter') ?>" class="input-text required-entry validate-email form-control" />
</div>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Subscribe') ?>" class="button"><span><span><?php echo $this->__('Subscribe') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var newsletterSubscriberFormDetail = new VarienForm('newsletter-validate-detail');
//]]>
</script>
Please check below solutions:
In the Magento backend "System > Permissions > Variables" and "System > Permissions > Blocks"
Add newsletter/subscribe and refreshed cache.
More info:
There is a new check on the template directive, see Mage_Core_Model_Email_Template_Filter::blockDirective() line 176
if ($this->_permissionBlock->isTypeAllowed($blockParameters['type'])) {
$type = $blockParameters['type'];
$block = $layout->createBlock($type, null, $blockParameters);
}
Also check in system configuration as below:
System--->Advanced--->Advanced

How do I access and create error messages

I have a login form. If I submit it without entering anything there should be an error message over the input fields.
How can I access the error-messages from the magento controller? How should I program the messages?
<form action="<?php echo $this->getPostActionUrl() ?>" method="post">
<?php echo $this->getBlockHtml('formkey'); ?>
<div class="block-content">
<?php echo $this->__('Save your Designs');?><br> <br>
<div class="col-reg registered-account">
<div class="email-input">
<label for="mini-login" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
<input title="<?php echo $this->__('User Name')?>" type="text" name="login[username]" id="mini-login" class="required-entry input-text" value="<?php echo $this->__('User Name')?>" onFocus="if(this.value != '') {this.value = '';}" onBlur="if (this.value == '') {this.value = '<?php echo $this->__('User Name')?>';}" />
</div>
<div class="pass-input">
<label for="mini-password" class="required"><em>*</em>test<?php echo $this->__('Password') ?></label>
<input title="<?php echo $this->__('Password')?>" type="password" name="login[password]" id="mini-password" class="input-text required-entry" value="........." onFocus="if(this.value != '') {this.value = '';}" onBlur="if (this.value == '') {this.value = '.........';}" />
</div>
<!--<div class="ft-link-p">
<a title="<?php echo $this->__('Forgot your password?')?>" href="<?php echo $this->getForgotPasswordUrl() ?>" class="f-left" target="_blank"><?php echo $this->__('Forgot your password?') ?></a>
</div>-->
<div class="actions">
<div class="submit-login">
<input title="<?php echo $this->__('Login')?>" type="submit" class="button btn-submit-login" name="submit" value="<?php echo $this->__('LOGIN') ?>" />
</div>
</div>
</div>
<div class="col-reg login-customer">
<h2><?php echo $this->__('Registration is free and easy!');?></h2>
<br>
<ul class="list-log">
<li><?php echo $this->__('Faster checkout');?></li>
<li><?php echo $this->__('save your own designs');?></li>
<li><?php echo $this->__('View and track orders and more');?></li>
</ul>
<a class="btn-reg-popup" title="<?php echo $this->__('Register')?>" href="<?php echo $this->getUrl('customer/account/create')?>"><?php echo $this->__('Create an account');?></a>
</div>
<div style="clear:both;"></div>
</div>
</form>
include below script in phtml file
<script type="text/javascript">
//<![CDATA[
var Form = new VarienForm('formid', true);
//]]>
</script>
to access in controller use
if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
$error = true;
}
if ($error) {
throw new Exception();
}

Add search fields to search bar magento

A friend has asked me to look at a website they had built (long story short they fell out so site didnt get finished). There is a search bar on the left hand side with 3 different search categories
Ive found the code for it in form.mini.phtml
<div id="search1">
<h3>
SEARCH >>>
</h3>
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<div id="label_area">
<div id="label_area">
</div>
<input type="text" name="label" id="label" value="Label >>>" onclick="if(this.value!='Label >>>'){ } else { this.value =''; } "size="15" class="text2">
</div>
<div id="label_area">
<div id="label_area">
</div>
<input type="text" name="artist" id="artist" value="Artists >>>" onclick="if(this.value!='Artists >>>'){ } else { this.value =''; } "size="15" class="text2">
</div>
<div id="label_area">
<div id="label_area">
</div>
<input id="search" type="text" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="text2" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" /></div>
<div id="label_area"> <input type="image" src="<?php echo $this->getSkinUrl('images/go.jpg')?>" />
</div>
</form>
</div>
<!--<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<div class="form-search">
<label for="search"><?php echo $this->__('Search:') ?></label>
<input id="search" type="text" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" class="input-text" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" />
<button type="submit" title="<?php echo $this->__('Search') ?>" class="button"><span><span><?php echo $this->__('Search') ?></span></span> </button>-->
<div id="search_autocomplete" class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('Keywords>>>>>>>') ?>');
searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
//]]>
</script>
<!-- </div>
</form>-->
It looks like the developer has hashed this together, My question is, how do go about getting the label/artist fields working? sorry for the clumsiness, Im a novice with PhP, Ive tried a couple of approaches with no joy, thank you very much in advance :)

How to add message after submitting form? PHP, Wordpress

I trying to make a feature, where the user recieves a message saying "Your changes have been saved" after the user has pressed "save changes". When the form is being submittet the page is just refreshed and not redirected to any other page.
I have tried several things but nothing seems to work. I am good at HTML but not PHP. I would love if any of you could help me out!
My code for my profile template is the folowing:
<div class="user-image">
<div class="bordered-image thick-border">
<?php echo get_avatar(ThemexUser::$data['user']['ID'], 200); ?>
</div>
<div class="user-image-uploader">
<form action="<?php echo themex_url(); ?>" enctype="multipart/form-data" method="POST">
<label for="avatar" class="button"><span class="button-icon upload"></span><?php _e('Skift billede','academy'); ?></label>
<input type="file" class="shifted" id="avatar" name="avatar" />
<input type="hidden" name="user_action" value="update_avatar" />
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" />
</form>
</div>
</div>
<div class="user-description">
<form action="<?php echo themex_url(); ?>" class="formatted-form" method="POST">
<div class="message">
<?php ThemexInterface::renderMessages(); ?>
</div>
<div class="sixcol column">
<div class="field-wrapper">
<input type="text" name="first_name" size="30" value="<?php echo ThemexUser::$data['user']['profile']['first_name']; ?>" placeholder="<?php _e('Fornavn','academy'); ?>" />
</div>
</div>
<div class="sixcol column last">
<div class="field-wrapper">
<input type="text" name="last_name" size="30" value="<?php echo ThemexUser::$data['user']['profile']['last_name']; ?>" placeholder="<?php _e('Efternavn','academy'); ?>" />
</div>
</div>
<div class="clear"></div>
<!-- ADRESSE -->
<?php if(!ThemexCore::checkOption('profile_signature')) { ?>
<div class="field-wrapper">
<input type="text" name="signature" value="<?php echo ThemexUser::$data['user']['profile']['signature']; ?>" placeholder="<?php _e('Adresse','academy'); ?>" />
</div>
<?php } ?>
<div class="user-fields">
<?php ThemexForm::renderData('profile', array(), ThemexUser::$data['user']['profile']); ?>
</div>
<?php } ?>
<span class="button-icon save"> </span><?php _e('Gem ændringer','academy'); ?>
<input type="hidden" name="user_action" value="update_profile" />
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" />
</form>
</div>
you are submitting to another url. So you can add something like the below to your functions file to display a message when the url is appended with msg. (you can account for multiple messages using the switch below, look it up) also you will need to add `?msg=yourmessagevariable' to your form action.
add_action('wp_print_scripts', 'notifcation', 100);
function notifcation () {
if($_GET['msg']) {
$message= sanitize_text_field($_GET['msg']);
switch($message) {
case 'reg-business':
$notehead= 'Please register first';
$msg= 'Please register your business before continuing';
break;
case 'nowvalid':
$notehead= "Congratulations";
$msg='You have successfully connected ';
break;
case 'Completed':
$notehead= 'Edited';
$msg='You have successfully edited your advert';
break;
}
?>
<section id="notification" class="notif notif-notice">
<h6 class="notif-title"><?php echo $notehead;?></h6>
<p><?php echo $msg; ?></p>
<div class="notif-controls">
Close
</div>
</section>
<script type="text/javascript">
jQuery(document).ready(function() {
setTimeout(function(){
jQuery('#notification').css('display', 'none');
},3000)
});
jQuery('.notif-close').click(function(e){
e.preventDefault();
jQuery(this).parent().parent().css('display', 'none');
})
</script>
<?php
}
}

A form element added using jQuery, but is not recognised by $_POST

<script type='text/javascript'>
$(document).ready(function() {
$("#specific_consultant_yes").click(function() {
$('.specific').show('slow');
$.post("<?php echo $this->url(array('controller'=>'appointment', 'action' =>'available'),'default',true)?>",{app_date:$("#App_date").val(),consultant:$("#Consultants").val()} ,function(data){
$(".new").html(data);
});
$("#App_date").change(function() {
$.post("<?php echo $this->url(array('controller'=>'appointment', 'action' =>'available'),'default',true)?>",
{app_date:$("#App_date").val(),consultant:$("#Consultants").val()} ,function(data){
$(".new").html(data);
});
});
$("#Consultants").change(function() {
$.post("<?php echo $this->url(array('controller'=>'appointment', 'action' =>'available'),'default',true)?>",{app_date:$("#App_date").val(),consultant:$("#Consultants").val()} ,function(data){
$(".new").html(data);
});
});
});
$("#specific_consultant_no").click(function() {
$('.specific').hide('slow');
});
});
</script>
<form name='update_form' id='update_form' method='POST' action="<?php echo $this->url(array('controller' => 'appointment', 'action' =>'updatesave'));?>">
<fieldset name='Appointment'>
<legend>New Appointment Details</legend>
<div class='field50Pct'>
<div class='fieldItemLabel'>
<label for=''>Specific Consultant</label>
</div>
<div class=fieldItemValue'>
<input type='radio' name='specific_consultant' id='specific_consultant_yes' value='yes'>Yes
<input type='radio' name='specific_consultant' id='specific_consultant_no' value='no'>No
</select>
</div>
</div>
<div class='clear'></div>
<div class='specific' style='display:none'>
<div class='field50Pct'>
<div class='fieldItemLabel'>
<label for=''>Appointment Date</label>
</div>
<div class=fieldItemValue'>
<select name='app_date' id='App_date'>
<?php
$today = time();
for($i = 0 ;$i < 15; $i++)
{
$date_t = date('d-M-Y',$today);
$date_v = date('d-m-Y',$today);
?>
<option value="<?php echo $date_t ?>"><?php echo $date_t ?></option>
<?php
$today = $today+(1*24*60*60);
} ?>
</select>
</div>
</div>
<div class='field50Pct'>
<div class='fieldItemLabel'>
<label for=''>Consultant</label>
</div>
<div class=fieldItemValue'>
<select name='consultants' id='Consultants'>
<?php foreach($this->consultantlist as $consultantlist){ ?>
<option value="<?php echo $consultantlist->getId() ?>"><?php echo $consultantlist->getFirstName() ?> <?php echo $consultantlist->getMiddleName() ?> <?php echo $consultantlist->getLastName() ?></option>
<?php } ?>
</select>
</div>
</div>
<div class='clear'></div>
<br/>
<div class='new'>
</div>
<div class='clear'></div>
<br/>
</div>
</fieldset>
<center><input type='submit' name='update_appointment' value='Update Appointment' onclick='return confirmSubmit();'></center>
</div>
</form>
and
available.phtml has code like
<?php
$afternoon_time = '11:00';
$myresult .= "<input type='text' name='slotddd' value='hai'>";
echo $myresult;
?>
the extra form element is getting added properly and its getting displayed..but when i submit the form..the element si not recognized in the $_POST ...how to solve this problem>
Where is the 1 item with class "new" located? Is it inside the form? If its not located inside the form then it won't be included.
For example:
<form action="/post.php" method="POST">
<input name="somename" value="somevalue"/>
</form>
Is not equal to:
<form action="/post.php" method="POST">
</form>
<input name="somename" value="somevalue"/>

Categories