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)
Related
I am getting this error,
A PHP Error was encountered
Severity: Notice
Message: Trying to get property 'post_title' of non-object.
I cannot get the form inputs to print on the page and cannot update. Please help!
So, I have tried to update each record and only artist users are able to do that. But I cannot figure out how to show the individual post on the form page. The records saves correctly and deletes but cannot update them.
Controller
function editpost($post_id)//Edit post page
{
if (!$this->session->Role =='member,artist')
{
redirect(base_url() . 'login');
}
$data['success'] = 0;
if( !empty($this->input->post('post_title')) ) {
$data['post_title'] = $this->input->post('post_title');
$data['post'] = $this->input->post('post');
$data['active'] = 1;
/* >> file attach */
View
<form action="<?= base_url()?>starter/editpost/" method="post" class="justify-
content-center" enctype='multipart/form-data'>
<div class="form-group">
<label class="sr-only">Title</label>
<input type="text" class="form-control" placeholder="Title"
name="post_title" value="<?php echo $post->post_title; ?>">
</div>
<div class="form-group">
<label class="sr-only">Description</label>
<textarea class="form-control" placeholder="Describe it" name="post" ><?
php echo $post->post; ?></textarea>
</div>
<div class="row py-4">
<div class="col-lg-6 mx-auto">
<!-- Upload image input-->
<!-- File Button -->
<div class="col-md-5">
<input name="main_img[]" type="file" accept="image/x-png,image/gif,image/jpeg">
</div>
<br>
<br>
<p style="padding-top: 15px"><span> </span><input class="submit" type="submit" name="update"
value="Publish" /></p>
</form>
use direct the variable because you are passing just values which you are posting from form.
//like :
//for post_title
<input type="text" class="form-control" placeholder="Title"
name="post_title" value="<?php echo $post_title; ?>">
// for description
textarea class="form-control" placeholder="Describe it" name="post" ><?
php echo $post; ?></textarea>
You don't need to pass the post data in controller you can get post data anywhere
<input type="text" class="form-control" placeholder="Title" name="post_title" value="<?php echo ($this->input->post('post_title')!='')?$this->input->post('post_title'):''; ?>">
I am trying to make a radio button with 2 options i.e. option A and Option B.
I have 2 text input ( A and B ) and some other text input that always has to be there.
Option A of the radio button has to make disappear text input (A) and show another text input (B). Option B should make this the opposite. ( disappear text input (B) and show another text input (A) )
I don't know how to make that 2 text inputs.
will appreciate some help.
<form class="user" id="RegisterForm" action="" method="post">
<? print("USER ROLE : ") ?>
<input type="radio" name="user_role" <?php if (isset($user_role) && $user_role=="A") echo "checked";?> value="A">A
<input type="radio" name="user_role" <?php if (isset($user_role) && $user_role=="B") echo "checked";?> value="B">B
//REST OF the code defines some text inputs that are always should show.
<?php if ($fullname_req != "-1") { ?>
<div class="form-group">
<input type="text" class="form-control form-control-user" id="displayname" name="fullname" placeholder="<?php _e('Display name', 'user-panel-pro') ?>">
</div>
<?php } ?>
<?php if ($firstname_req != "-1") { ?>
<div class="form-group row">
<?php if ($firstname_req != "-1" or $lastname_req != "-1") { ?>
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="text" class="form-control form-control-user" id="First-Name" name="firstname" placeholder="<?php _e('first name', 'user-panel-pro') ?>">
</div>
<?php } ?>
<?php if ($lastname_req != "-1") { ?>
<div class="col-sm-6">
<input type="text" class="form-control form-control-user" id="Last-Name" name="lastname" placeholder="<?php _e('last name', 'user-panel-pro') ?>">
</div>
<?php } ?>
</div>
<?php } ?>
<?php if ($username_req != "-1") { ?>
<div class="form-group">
<input type="text" class="form-control form-control-user" id="User-Name" name="username" placeholder="<?php _e('Username', 'user-panel-pro') ?>">
</div>
<?php } ?>
<?php if ($email_req != "-1") { ?>
<div class="form-group">
<input type="email" class="form-control form-control-user" id="Email" name="email" placeholder="<?php _e('Email', 'user-panel-pro') ?>">
</div>
<?php } ?>
I am not able to understand your code, so I am just giving a small demo
<div class="radioBtns">
<label for='rbtnLoginTypeMobile'><input checked type="radio" id="rbtnLoginTypeMobile" name="rbtnLoginType" value='1' onclick="showLogin(1)"/><span>Mobile</span></label>
<label for='rbtnLoginTypeEmail'><input type="radio" id="rbtnLoginTypeEmail" name="rbtnLoginType" value='0' onclick="showLogin(0)" /><span>Email</span></label>
</div>
<div class="mobilelogin">Your Mobile Div</div>
<div class="emaillogin">Your Email Div</div>
<script type="text/javascript">
function showLogin(val)
{
if(val==1)
{
$('.emaillogin').css('display','none');
$('.mobilelogin').css('display','');
}
else
{
$('.mobilelogin').css('display','none');
$('.emaillogin').css('display','');
}
}
</script>
What i am trying to do is:
post a form when user is logged in.
but if he is not logged in then pop up login is shown to user.
and in that popup redirection URL is added to hidden field.
when popup opens and i login it redirect me to that form.
But when i try to submit form it not being submitted.
// submit button in form
$('#submitcompanyEnquiry').on('click',function(e){
e.preventDefault();
//get data attr to check if user is login
if($('#companyEnquiry').data('login')){
//companyEnquiry =>form id
//here i try to submit form
console.log('testing'); --->it is working
jQuery('#companyEnquiry').submit(); ---> //the problem is here this piece of code is executing
}else{
if($('#companyEnquiry').attr('action')!=''){
//here i added the current url to hidden field latter to used for redirection
$('#loginForm #redirectUrl').val($('#companyEnquiry').data('seotitle'));
}
//here the login popup is trigger.
jQuery("#login").trigger('click');
}
});
Things that I confirmed:
ensure that there is unique id with the
name provided.
console some value in the if block which was
running but the line of code i have mention.
PHP part is working fine i have removed the e.preventDefault();
it is works fine but doesn't achieve the require functionality.
HTML Code
<form action="<?=Route::url('default',array('controller'=>'contact','action'=>'user_contact'))?>" data-login="<?php echo $data; ?>" data-seotitle="<?=Route::url('company', array('controller'=>'listing','seotitle'=>$company_seotitle))?>" id="companyEnquiry" method="post">
<input type="hidden" name="company_to" value="<?php echo $id; ?>">
<?php if (!$auth->logged_in()) { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="Name" name="name" required aria-describedby="basic-addon1">
</div>
<?php }else { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="Name" required value="<?php echo $auth->get_user()->company_name; ?>" name="name" aria-describedby="basic-addon1">
</div>
<?php } ?>
<?php if (!$auth->logged_in()) { ?>
<div class="input-group searchbox">
<input type="email" class="form-control search" placeholder="email" required name="company_from" aria-describedby="basic-addon1">
</div>
<?php }else { ?>
<div class="input-group searchbox">
<input type="email" class="form-control search" placeholder="email" required value="<?php echo $auth->get_user()->companyemail; ?>" name="company_from" aria-describedby="basic-addon1">
</div>
<?php } ?>
<?php if ($auth->logged_in()) { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="phone number" required name="phone" value="<?php echo $auth->get_user()->company_phone_1; ?>" aria-describedby="basic-addon1">
</div>
<?php } else { ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="phone number" required name="phone" aria-describedby="basic-addon1">
</div>
<?php } ?>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="subject" required name="subject" aria-describedby="basic-addon1">
</div>
<div class="input-group searchbox">
<input type="text" class="form-control search" placeholder="message" required name="message" aria-describedby="basic-addon1">
</div>
<input data-login="<?php echo $data; ?>" id="submitcompanyEnquiry" type="submit" name="submit" value="SEND" class="form-control blue-btn send-btn">
</form>
The problem can only exist in the way you are adding the login variable to the form with the id : companyEnquiry
Check if you have add it as correct parameter because jquerys data function will only read values which have a "data-" tag infront of it.
So your php code should look like this :
echo '<form id="companyEnquiry" ' . ($login ? 'data-login="1"' : '' . '>
So I needed 2 new fields for this contact form, so I went into the contact.php in the shortcodes folder of the wordpress theme, and edited it to display on the website. It looks good on the site, but when I fill out the form and submit it, only the default fields get sent to my email address.
Here is the website, and below is the code: http://sellhouseforcashorlando.com/contact/
// Contact Form
add_shortcode('contact_form', 'theme_shortcode_contact_form');
function theme_shortcode_contact_form($atts, $content = null, $code) {
extract(shortcode_atts(array(
'mail_to' => '',
'form_id' => false,
'button_color' => 'black'
), $atts));
$id = mt_rand(0, 1000);
$template_directory = get_template_directory_uri();
$ajax_url = admin_url('admin-ajax.php');
$mail_to = str_replace('#','[at]',$mail_to);
$name_text = __('Name', 'theme_front');
$email_text = __('Email', 'theme_front');
$phonenumber_text = __('Phone Number', 'theme_front');
$address_text = __('Property Address', 'theme_front');
$message_text = __('Message', 'theme_front');
$submit_text = __('Submit', 'theme_front');
$form_id = ( $form_id ) ? '<input type="hidden" name="form-id" value="' . $form_id . '" />' : '';
return <<<RET
[raw]
<form method="post" action="$ajax_url" id="form-$id" class="contact-form ajax-form validate-form">
<div class="form-input-item clearfix">
<label for="contact-form-$id-contact-name">$name_text <span class="required-star">*</span></label>
<input type="text" class="input-text" name="contact-name-h" id="contact-form-contact-name-h">
<input type="text" tabindex="8" size="22" value="" class="input-text {required:true}" name="contact-name" id="contact-form-$id-contact-name">
<div class="form-error-box"></div>
</div>
<div class="form-input-item clearfix">
<label for="contact-form-$id-contact-email">$email_text <span class="required-star">*</span></label>
<input type="text" tabindex="9" size="22" value="" class="input-text {required:true, email:true}" name="contact-email" id="contact-form-$id-contact-email">
<div class="form-error-box"></div>
</div>
<div class="form-input-item clearfix">
<label for="contact-form-$id-contact-phonenumber">$phonenumber_text <span class="required-star">*</span></label>
<input type="text" tabindex="9" size="22" value="" class="input-text {required:true}" name="contact-phonenumber" id="contact-form-$id-contact-phonenumber">
<div class="form-error-box"></div>
</div>
<div class="form-input-item clearfix">
<label for="contact-form-$id-contact-address">$address_text <span class="required-star">*</span></label>
<input type="text" tabindex="9" size="22" value="" class="input-text {required:true}" name="contact-address" id="contact-form-$id-contact-address">
<div class="form-error-box"></div>
</div>
<div class="form-input-item clearfix">
<label for="contact-form-$id-contact-content">$message_text <span class="required-star">*</span></label>
<textarea tabindex="10" rows="3" cols="30" class="input-textarea {required:true}" id="contact-form-$id-contact-content" name="contact-content"></textarea>
<div class="form-error-box"></div>
</div>
<div class="form-response"></div>
<div class="form-input-item form-input-item-last clearfix">
<button class="button medium $button_color" type="submit"><span>$submit_text</span></button>
</div>
$form_id
<input type="hidden" name="mail_to" value="$mail_to">
<input type="hidden" name="action" value="do_contact" />
</form>
So I am working on a file upload form that seems to lose the information in the file super global from one step to another. So what I do is I print out the file super global before I verify through captcha and then print it out once I validate through the captcha. For some way I lose the information after verifying the captcha. I have tried storing the information in a cookie and a session variable but with no luck. In terms of the cookie direction it saves the file super global information into the cookie only if I hit refresh before captcha validation. In terms of session storage it stores the information in the session variable before I verify the captch but then lose it after I verify the captach. Can you guys people help, and thanks in advance. My code is below:
$DIRECTORY_NAME = "/home/www/xxx/xxxPhotos/";
$FILES = array();
$SPEAKER_STATUS_DROPDOWN = '<option value="">...</option><option value="Suggested">Suggested</option><option value="Invited">Invited</option><option value="Confirmed">Confirmed</option>';
if (empty($_SESSION['captcha']) || strtolower(trim($_REQUEST['captcha'])) != $_SESSION['captcha']) {
$captcha = false;
} else {
$captcha = true;
}
if (!empty($_POST) && $captcha) {
$UNIQ_ID = $_POST['uniq_id'];
$FORM_ID = $_POST['form_id'];
//$uniqid = createuniqid();
// Upload file
if ($_FILES["file"]["name"] != "") {
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
die();
}
else
{
$allowedExtensions = array("jpg","gif","tiff","pdf");
if ($file["file"]['tmp_name'] != '') {
if (!in_array(end(explode(".",
strtolower($file["file"]['name']))),
$allowedExtensions)) {
die($file["file"]['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<< Go Back</a>');
}
}
$filename = "AS_".$uniqid."". strrchr($_FILES["file"]["name"], '.');
move_uploaded_file($_FILES["file"]["tmp_name"],
$DIRECTORY_NAME . $filename);
$filenamequery = ", attachment='$filename' ";
$filenameemailbody = "<br>Attachment: http://www.verney.ca/viewabstract.php?filename=$filename";
}
die('reached here');
}
HTML Form
<form name="frmAbstract" id ="frmAbstract" method="post" action="storiesv.php" onSubmit="return validation();" enctype="multipart/form-data" style="margin-left:20px;">
<input type="hidden" name="uniq_id" value="">
<input type="hidden" name="form_id" value="6">
<div><label class="labelHeader"><strong><h1>Form</h1></strong></label><br/></div>
<div class="formrow">
<label for="question_390">First Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_390" name="question_390" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_391">Last Name of Submitter: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_391" name="question_391" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_392">Title: </label>
<input type="text" id="question_392" name="question_392" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_393">Organization: </label>
<input type="text" id="question_393" name="question_393" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_394">Phone: </label>
<input type="text" id="question_394" name="question_394" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_395">Email: <span style="color:#FF0000">*</span></label>
<input type="text" id="question_395" name="question_395" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_396">Involvement with the CBS: </label>
<input type="text" id="question_396" name="question_396" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_397">First became a CBS member in (yyyy): <span style="color:#FF0000">*</span></label>
<input type="text" id="question_397" name="question_397" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_398">Your story/experience/anecdote (limit of 250 words): </label>
<textarea name="question_398" name="question_398" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do you have a photo / graphic to upload (scans of print photos are acceptable)? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_0" name="question_399[]" value="Yes"><label for="question_399_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_399_1" name="question_399[]" value="No"><label for="question_399_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div>
<div>
<label for="question_400">Attachment: (Only jpg, gif, tiff, pdf, will be accepted) </label>
<input type="file" id="question_400" name="question_400" style="width:500px;">
</div>
<div class="formrow">
<label for="question_401">For photos submitted, please include names of people in the photo, location, and date. </label>
<textarea name="question_401" name="question_401" style="width:500px;height:200px;"></textarea>
</div>
<div class="formrow" >
<label>Do we have permission to publish this photo in a slide show to be featured at the 2014 CBS Conference and possibly in a printed collection of memoirs intended for past and present CBS members? </label>
<div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_0" name="question_402[]" value="Yes"><label for="question_402_0">Yes</label></div><div class="checkboxdiv"><input type="radio" style="width:20px;float:left;border:0px;"id="question_402_1" name="question_402[]" value="No"><label for="question_402_1">No</label></div><strong><em></em></strong><div style="clear:both;"></div></div><div><label class="labelHeader"><strong>Questions</strong></label><br/></div>
<div class="formrow">
<label for="question_404">Tell us about your experience(s) with the CBS. </label>
<input type="text" id="question_404" name="question_404" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_405">How did you become involved in the CBS? </label>
<input type="text" id="question_405" name="question_405" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_406">What is your best memory of the CBS? </label>
<input type="text" id="question_406" name="question_406" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_407">Who have been your role models in the field? </label>
<input type="text" id="question_407" name="question_407" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_408">What has been the most significant accomplishment of Canadian bioethics? </label>
<input type="text" id="question_408" name="question_408" style="width:500px" maxlength="255" value="">
</div>
<div class="formrow">
<label for="question_409">What is our biggest challenge going forward? </label>
<input type="text" id="question_409" name="question_409" style="width:500px" maxlength="255" value="">
</div>
</fieldset>
<div style="clear:both;"><br><input type="submit" name="btnSave" id="btnSave" value="Next" class="submitbutton" "></div>
<p> </p>
</form>
So the code above is the original code I have been working with. It essentially does the file upload after the captcha is validated, and this is where I lose $_FILES super global
ANSWER: Thanks for all those who viewed my question. The issue was the captcha was in a form on it own page with a enctype set. Therefore the $_FILES super global was overwritten with that forms $_FILES, which of course is not set.
The name of your file input is question_400, so you would need $_FILES["question_400"]["name"], etc.