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();
}
Related
post id is the common field in both the tables.If I want to select the comments under same post_id,only 1 time the post should display and all its comments under it..
this is my code....
home.php
<?php
$sql="SELECT family_news.post_id,family_news.username,family_news.post,
family_news.fileToUpload,family_news.description,
family_comments.post_id,family_comments.comment,
family_comments.commenter
FROM family_news
LEFT JOIN family_comments ON family_news.post_id = family_comments.post_id
ORDER BY family_news.post_id DESC";
if($result = mysqli_query($con, $sql))
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="form-group">
<b style="font-size:30px;color:brown;">
<?php
echo $row['username'];
?>
</b>
<br>
<?php
if($row['fileToUpload'] != NULL)
{
?>
<form action="post_comment.php" method="POST">
<input class="form-control" type="hidden" name="post_id" value="<?php echo $row['post_id']; ?>">
<br>
<img class="img-responsive" src="../admin_panel/uploads/<?php echo $row['fileToUpload']; ?>" alt="Image Loading" height='80' width='120'>
<div class="form-group" style="font-size:15px;color:purple;">
<?php
echo $row['description'];
?>
<br>
<h3 style="color:black">Comments</h3>
<h3 style="color:red">
<?php
echo $row['commenter'];
?>
</h3>
<h4 style="color:saddlebrown">
<?php
echo $row['comment'];
?>
</h4>
<br>
<input class="form-control" type="text" name="comment" placeholder="Write a comment">
<br>
<input class="form-control" type="hidden" name="commenter" value="<?php echo $_SESSION['uname']; ?>">
<input type="submit" class="btn btn-primary" value="Post">
</div>
</form>
<?php
}
if($row['post'] != NULL)
{
?>
<br>
<div class="form-group" style="font-size:15px;color:purple;">
<form action="post_comment.php" method="POST">
<input class="form-control" type="hidden" name="post_id" value="<?php echo $row['post_id']; ?>">
<?php
echo $row['post'];
?>
<br>
<h3 style="color:black">Comments</h3>
<h3 style="color:red">
<?php
echo $row['commenter'];
?>
</h3>
<h4 style="color:saddlebrown">
<?php
echo $row['comment'];
?>
</h4>
<br>
<input class="form-control" type="text" name="comment" placeholder="Write a comment">
<br>
<input class="form-control" type="hidden" name="commenter" value="<?php echo $_SESSION['uname']; ?>">
<input type="submit" class="btn btn-primary" value="Post">
</form>
<?php
}
?>
</div>
<?php
}
}
?>
</div>
</section>
post_comment.php
<section class="col-lg-6 connectedSortable">
<?php
$post_id=$_POST['post_id'];
$comment=$_POST['comment'];
$commenter=$_POST['commenter'];
if($comment != NULL) {
$sql="INSERT INTO family_comments
(post_id, comment, commenter)
VALUES ('$post_id', '$comment', '$commenter')";
if($con ->query($sql) == TRUE)
{
echo 'Comment saved Successfully...';
}
} else {
echo 'Please Write Something...';
}
?>
</section>
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>
// how will i redirect this page after successful submission of the form it takes the user to homepage?? this is the website : http://shambas.co.ke/shambaz/submit-property/
<?php
if($submitted_successfully){
$submit_message = get_option('theme_submit_message');
alert( __('Success:','framework'), $submit_message );
}
elseif($updated_successfully){
alert( __('Success:','framework'),__('Property updated successfully!','framework') );
}
else{
/* if passed parameter is properly set to edit property */
if(isset($_GET['edit_property']) && !empty($_GET['edit_property'])){
$edit_property_id = intval(trim($_GET['edit_property']));
$target_property = get_post($edit_property_id);
/* check if passed id is a proper property post */
if( !empty( $target_property ) && ( $target_property->post_type == 'property' ) ){
// Check Author
global $current_user;
get_currentuserinfo();
/* check if current logged in user is the author of property */
if( $target_property->post_author == $current_user->ID ){
$post_meta_data = get_post_custom( $target_property->ID );
?>
<form id="submit-property-form" class="submit-form" enctype="multipart/form-data" method="post">
<div class="row-fluid">
<div class="span6">
<div class="form-option">
<label for="title"><?php _e('Property Title','framework'); ?></label>
<input id="title" name="title" type="text" class="required" value="<?php echo $target_property->post_title; ?>" title="<?php _e( '* Please provide property title!', 'framework'); ?>" autofocus required/>
</div>
<div class="form-option">
<label for="description"><?php _e('Property Description','framework'); ?></label>
<textarea name="description" id="description" cols="30" rows="5"><?php echo $target_property->post_content; ?></textarea>
</div>
<div class="form-options-container clearfix">
<div class="form-option ">
<label for="city"><?php _e('Location', 'framework'); ?></label>
<span class="selectwrap">
<select name="city" id="city" class="search-select">
<?php edit_form_hierarchichal_options( $target_property->ID, 'property-city'); ?>
</select>
</span>
</div>
<div class="form-option right">
<label for="status"><?php _e('Status', 'framework'); ?></label>
<span class="selectwrap">
<select name="status" id="status" class="search-select">
<?php edit_form_taxonomy_options( $target_property->ID, 'property-status'); ?>
</select>
</span>
</div>
<div class="form-option">
<label for="price"><?php _e('Price','framework'); ?></label>
<input id="price" name="price" type="text" value="<?php if( isset($post_meta_data['REAL_HOMES_property_price']) ){ echo $post_meta_data['REAL_HOMES_property_price'][0]; } ?>" title="<?php _e( '* Please provide the value in only digits!', 'framework'); ?>" />
</div>
<div class="form-option right">
<label for="size"><?php _e('Property Size','framework'); ?></label>
<input id="size" name="text" type="text" value="<?php if( isset($post_meta_data['REAL_HOMES_property_size']) ){ echo $post_meta_data['REAL_HOMES_property_size'][0]; } ?>" title="<?php _e( '* Please provide the value in only digits!', 'framework'); ?>" />
</div>
</div>
<div class="form-option">
<label for="featured"><?php _e('Mark this Property as Featured','framework'); ?></label>
<input id="featured" name="featured" type="checkbox" <?php if( isset($post_meta_data['REAL_HOMES_featured']) && $post_meta_data['REAL_HOMES_featured'][0] == 1 ){ echo 'checked';} ?>/>
</div>
</div>
<div class="span6">
<div class="form-option">
<label for="address"><?php _e('Address', 'framework'); ?></label>
<input type="text" class="required" name="address" id="address" value="<?php if( isset( $post_meta_data['REAL_HOMES_property_address'] ) ){ echo $post_meta_data['REAL_HOMES_property_address'][0]; } ?>" title="<?php _e( '* Please provide a property address!', 'framework'); ?>" required/>
<div class="map-wrapper">
<button class="real-btn goto-address-button" type="button" value="address"><?php _e( 'Find Address','framework' ); ?></button>
<div class="map-canvas"></div>
<input type="hidden" name="location" class="map-coordinate" value="<?php if( isset( $post_meta_data['REAL_HOMES_property_location'] ) ){ echo $post_meta_data['REAL_HOMES_property_location'][0]; } ?>" />
</div>
</div>
<div class="form-option">
<label for="featured-image"><?php _e('Property Featured Image','framework'); ?></label>
<div id="featured-thumb-container" class="clearfix">
<?php
if( has_post_thumbnail( $target_property->ID ) ){
echo '<div class="gallery-thumb">';
echo get_the_post_thumbnail( $target_property->ID, 'thumbnail' );
echo '<a class="remove-featured-image" data-property-id="'.$target_property->ID.'" href="'. site_url("/wp-admin/admin-ajax.php") .'" ><i class="fa fa-trash-o"></i></a>';
echo '<span class="loader"><i class="fa fa-spinner fa-spin"></i></span>';
echo '</div>';
}
?>
</div>
<div id="featured-file-container" class="<?php if(has_post_thumbnail( $target_property->ID )){ echo "hidden"; }?>" >
<input id="featured-image" name="featured_image" type="file" title="<?php _e( '* Please provide image with proper extension! Only .jpg .gif and .png are allowed.!', 'framework'); ?>" class="image required" required/>
<div class="field-description">
<?php _e('Image should have minimum width of 770px and minimum height of 386px. ( Bigger image will be cropped automatically )','framework'); ?>
</div>
</div>
</div>
<div class="form-option">
<label><?php _e('Gallery Images','framework'); ?></label>
<div id="gallery-thumbs-container" class="clearfix">
<?php
$thumbnail_size = 'thumbnail';
$properties_images = rwmb_meta( 'REAL_HOMES_property_images', 'type=plupload_image&size='.$thumbnail_size, $target_property->ID );
if( !empty($properties_images) ){
foreach( $properties_images as $prop_image_id=>$prop_image_meta ){
echo '<div class="gallery-thumb">';
echo '<img src="'.$prop_image_meta['url'].'" alt="'.$prop_image_meta['title'].'" />';
echo '<a class="remove-image" data-property-id="'.$target_property->ID.'" data-gallery-img-id="'.$prop_image_id.'" href="'. site_url("/wp-admin/admin-ajax.php") .'" ><i class="fa fa-trash-o"></i></a>';
echo '<span class="loader"><i class="fa fa-spinner fa-spin"></i></span>';
echo '</div>';
}
}
?>
</div>
<label><?php _e('Add more images to gallery','framework'); ?></label>
<div id="gallery-images-container">
<div class="controls-holder"><input class="gallery-image image" name="gallery_image_1" type="file" /></div>
</div>
<button id="add-more" class="real-btn"><?php _e('Add More','framework'); ?></button>
<div class="field-description">
<?php _e('Provide images for gallery on property detail page. Images should have minimum width of 770px and minimum height of 386px. ( Bigger images will be cropped automatically )','framework'); ?>
</div>
</div>
<div class="form-option">
<label><?php _e('What to display in agent information box ?','framework');?></label>
<div class="agent-options">
<input id="agent_option_none" type="radio" name="agent_display_option" value="none" <?php if( isset($post_meta_data['REAL_HOMES_agent_display_option']) && ($post_meta_data['REAL_HOMES_agent_display_option'][0] == "none") ){ echo "checked"; } ?> />
<label for="agent_option_none"><?php _e('None','framework'); ?></label> <small><?php _e('( Agent information box will not be displayed )','framework'); ?></small>
<br/>
<input id="agent_option_profile" type="radio" name="agent_display_option" value="my_profile_info" <?php if( isset($post_meta_data['REAL_HOMES_agent_display_option']) && ($post_meta_data['REAL_HOMES_agent_display_option'][0] == "my_profile_info") ){ echo "checked"; } ?> />
<label for="agent_option_profile"><?php _e('My profile information','framework');?></label> <small> <?php _e('( You can add your profile information here )','framework');?></small>
<br/>
<input id="agent_option_agent" type="radio" name="agent_display_option" value="agent_info" <?php if( isset($post_meta_data['REAL_HOMES_agent_display_option']) && ($post_meta_data['REAL_HOMES_agent_display_option'][0] == "agent_info") ){ echo "checked"; } ?> />
<label for="agent_option_agent"><?php _e('Display an agent\'s information','framework'); ?></label>
<select name="agent_id" id="agent-selectbox">
<?php generate_posts_list('agent',$post_meta_data['REAL_HOMES_agents'][0]); ?>
</select>
</div>
</div>
<div class="form-option">
<?php wp_nonce_field( 'submit_property', 'property_nonce' ); ?>
<input type="hidden" name="action" value="update_property"/>
<input type="hidden" name="property_id" value="<?php echo $target_property->ID; ?>"/>
<input type="submit" value="<?php _e('Submit Property','framework');?>" class="real-btn" />
</div>
Have you tried to use
header("location:thepagethatyouwantreach.php");
in the case that the form it's correctly submitted?
//controlls
/if submission it's ok
header("location:thepagethatyouwantreach.php"); //redirect the user
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
}
}
I'm working on a new site build and the site has two contact forms which run off the same controller. At the moment the form on the contact page loads a small message saying 'thanks for your inquiry' etc.. The form on the 'gallery' page, once it's submitted sends the user to the contact page and displays the same message.
However what I want is to keep the user on the page they are currently on and then display the message. Exactly what's currently happening on the contact page.
If I change this piece of code:
$this->_redirect('*/*/');
in /code/core/Mage/Contacts/controllers/IndexController.php I can get it to re-direct to the homepage etc but I just want it to display the message on the page i'm on.
Here is the code to my form:
<form action="<?php echo Mage::getUrl(); ?>contacts/index/post/" id="contactForm" method="post">
<input type='hidden' name='formtype' value='Contact Us Page'/>
<div class="fieldset">
<ul class="form-list">
<li class="fields">
<div class="field">
<div class="input-box">
<input onfocus="if(this.value == 'Name'){this.value = '';}" name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" class="input-text required-entry" type="text" onblur="if(this.value == ''){this.value='Name';}" value="Name"/>
</div>
</div>
<li>
<div class="input-box">
<input name="company" id="company" onfocus="if(this.value == 'Company'){this.value = '';}" title="<?php echo Mage::helper('contacts')->__('Company') ?>" value="Company" onblur="if(this.value == ''){this.value='Company';}" class="input-text" type="text" />
</div>
</li>
<div class="field">
<div class="input-box">
<input name="email" id="email" onfocus="if(this.value == 'Email'){this.value = '';}" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="Email" onblur="if(this.value == ''){this.value='Email';}" class="input-text required-entry validate-email" type="text" />
</div>
</div>
</li>
<li class="wide">
<!--<label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>-->
<div class="input-box">
<textarea name="comment" id="comment" onfocus="if(this.value == 'Enquiry details'){this.value = '';}" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" onblur="if(this.value == ''){this.value='Enquiry details';}" cols="5" value="Enquiry details" rows="3">Enquiry details</textarea>
</div>
</li>
</ul>
</div>
<div class="buttons-set">
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
<button class="submit" type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var contactForm = new VarienForm('contactForm', true);
//]]>
</script>
You could try using the referer URL
in /code/core/Mage/Contacts/controllers/IndexController.php
if(Mage::helper('core/http')->getHttpReferer(true)){
$this->_redirectUrl(Mage::helper('core/http')->getHttpReferer(true));
}
else{
$this->_redirect('*/*/');
}
Magento useful functions cheatsheet
Also you should avoid making changes to core, Take a look # Magento: Overriding Core Files (Blocks, Models, Resources, Controllers)