Changing some text in the Fivestar module - drupal

I'm using the Fivestar module in Drupal 6...
http://drupal.org/project/fivestar
And, I want to change the text:
From: Average: *****
To This: Rate this Article: *****
I'd rather not hack the module of use string overrides, I'm hoping to use a hook_form_alter function or something similar in the template.php file.
Here's is what the HTML looks like:
<form action="/fall-foliage" accept-charset="UTF-8" method="post" id="fivestar-form-node-232" class="fivestar-widget"><div>
<div class="fivestar-form-vote-232 clear-block"><input type="hidden" name="content_type" id="edit-content-type" value="node" />
<input type="hidden" name="content_id" id="edit-content-id" value="232" /><div class="fivestar-form-item fivestar-average-stars fivestar-labels-hover">
<div class="form-item" id="edit-vote-wrapper">
<label for="edit-vote">Average: </label>
...etc...
Code in fivestar.module looks like this:
function theme_fivestar_summary($user_rating, $average_rating, $votes, $stars = 5, $feedback = TRUE) {
$output = '';
$div_class = '';
if (isset($user_rating)) {
$div_class = isset($votes) ? 'user-count' : 'user';
$user_stars = round(($user_rating * $stars) / 100, 1);
$output .= '<span class="user-rating">'. t('Your rating: <span>!stars</span>', array('!stars' => $user_rating ? $user_stars : t('None'))) .'</span>';
}
if (isset($user_rating) && isset($average_rating)) {
$output .= ' ';
}
if (isset($average_rating)) {
$div_class = isset($votes) ? 'average-count' : 'average';
$average_stars = round(($average_rating * $stars) / 100, 1);
$output .= '<span class="average-rating">'. t('Average: <span>!stars</span>', array('!stars' => $average_stars)) .'</span>';
}

in fivestar.module file search for 'Average' not 'average' and can change as per your wise, But changing core module file is not recommend(Whenever you update your module, changes revert back).
Please create custom module and implement hook_form_alter
Example:
function YourModuleName_form_alter(&$form, $form_state, $form_id)
Print $form and search for 'Average'
change $form[xyz][xyz] = 'Average' to $form[xyz][xyz] = 'Rate this Article'
if is not form, use hook_nodeapi

Related

How to make form non required?

I have one issue, to make custom field non-required field. I use Magee Restaurant plugin for Wordpress, and when try to checkout, there is one field named "Table Number". For default that field is required. How to make non-required?
Label is named:
<p class="form-row form-row-wide validate-required" id="mgrt_table_num_dine_field" data-priority=""><label for="mgrt_table_num_dine" class="">Table Number <abbr class="required" title="required">*</abbr></label><input type="text" class="input-text " name="mgrt_table_num_dine" id="mgrt_table_num_dine" placeholder="Insert your table number." value=""></p>
Thanks.
Good thing that plugin is using woocommerce_form_field function. In that case we can use it's filter. This should do it.
add_filter( 'woocommerce_form_field_args', 'magee_table_number_field_args', 10, 3 );
function magee_table_number_field_args( $args, $key, $value ){
if ( $key == 'mgrt_table_num_dine' ) {
$args['required'] = false;
}
return $args;
}

Form Block - add help text to form input

I'm trying to add a 'help text' to the questions added by the Form block.
Something like this but on the front-end part of the form.
For some reason its not saving the value or getting the value into the edit form. Even when I add it manually to the row it is not in the frontend output.
I made a custom form block / template with the additional changes to:
An extra table column 'helptext' in the db.xml. And updated the block.
<table name="btFormQuestions">
...
<field name="helptext" type="text">
<default value=""/>
</field>
...
</table>
An extra field on the editing form (normal and edit):
<div class="form-group">
<?php echo $form->label('helptext', t('Help Text'))?>
<?php echo $form->text('helptext', array('maxlength' => '255'))?>
</div>
Output it In the view.php
use \Application\Block\Form\MiniSurvey;
...
<?php echo $question['helptext']; ?>
Added the extra code to auto.js,
addQuestion:
postStr += '&helptext=' + encodeURIComponent($('#helptext' + mode).val());
...
reloadQuestion:
$('#helptextEdit').val(jsonObj.helptext);
...
resetQuestion:
$('#helptext').val('');
mini-survey.php,
$dataValues = array(
intval($values['qsID']),
trim($values['question']),
trim($values['helptext']),
$values['inputType'],
$values['options'],
intval($values['position']),
$width,
$height,
intval($values['required']),
$values['defaultDate'],
intval($values['msqID']),
);
$sql = 'UPDATE btFormQuestions SET questionSetId=?, question=?, helptext=?, inputType=?, options=?, position=?, width=?, height=?, required=?, defaultDate=? WHERE msqID=? AND bID=0';
} else {
if (!isset($values['position'])) {
$values['position'] = 1000;
}
if (!intval($values['msqID'])) {
$values['msqID'] = intval($this->db->fetchColumn("SELECT MAX(msqID) FROM btFormQuestions") + 1);
}
$dataValues = array(
$values['msqID'],
intval($values['qsID']),
trim($values['question']),
trim($values['helptext']),
$values['inputType'],
$values['options'],
intval($values['position']),
intval($values['width']),
intval($values['height']),
intval($values['required']),
$values['defaultDate'],
);
$sql = 'INSERT INTO btFormQuestions (msqID,questionSetId,question,helptext,inputType,options,position,width,height,required,defaultDate) VALUES (?,?,?,?,?,?,?,?,?,?,?)';
}
$result = $this->db->executeQuery($sql, $dataValues);
Cleared cache and updated the block.
Forum Post on Concrete5 with the changes
Solved:
Got this working on a clean install of C5.
Small changes:
Added the original files form the concrete/blocks/form to the application folder (and changed the namespace)
db.xml (longtext was unnecessary)
<field name="helptext" type="text" size="65535"></field>
auto.js (Semicolon ; missing in the original concrete/block/form/auto.js (and thus the copy in application))
reloadQuestion:
$('#editQuestionForm').css('display', 'block');

Option page not updating multiple records in settings api

Hi i am new to wordpress plugin development. i have issues with settings api. please help if you can.
Below is my problem.
The problem i am facing is the last record which is link it is updating in database but the title text is not updating in database.
So please help me find solution. Thank you.
function load_plugin() {
add_settings_section('plugin_main', '<h1>Ticker Settings</h1>', 'plugin_section_text', 'plugin');
add_settings_field('plugin_text_string', 'Title text', 'plugin_setting_string', 'plugin', 'plugin_main');
add_settings_field('post_title_link', 'Link', 'plugin_link_setting', 'plugin', 'plugin_main');
register_setting('plugin_options', 'plugin_options');
register_setting('post_title_link', 'post_title_link');
}
function plugin_section_text() {
echo '<p>Change your post ticker title and give link to.</p>';
}
function plugin_setting_string() {
echo "<input id='plugin_text_string' name='plugin_options' size='40'
type='text' value='" . get_option('plugin_options') . "' />";
}
function plugin_link_setting() {
echo "<input id='post_title_link' name='post_title_link' size='40'
type='text' value='" . get_option('post_title_link') . "' />";
}
add_action('admin_init', 'load_plugin');
function post_ticker_setting() {
?>
<div class="wrap">
<form action="options.php" method="post">
<?php
settings_fields('plugin_options');
settings_fields('post_title_link');
do_settings_sections('plugin');
?>
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</form>
</div>
<?php
}
You have to register all settings with register_setting (https://codex.wordpress.org/Function_Reference/add_settings_field). The register_setting lines you show don't correspond to your fields.
Also sections should be declared after the fields are registered (https://codex.wordpress.org/Function_Reference/register_setting)
In your code, the following lines
<?php
settings_fields('plugin_options');
settings_fields('post_title_link');
do_settings_sections('plugin');
?>
don't correspond to the declarations above:
add_settings_section('plugin_main', ...
add_settings_field('plugin_text_string', ...
add_settings_field('post_title_link', ...
Only the 'post_title_link' has the same name. Which is probably why it is the only one updating.

Wordpress Email Form

Wordpress Email Form
Hi all
I've been using this sort of email form in a number of sites and it's always worked.
I've tried to use it in a Wordpress site but it won't
Is there any obvious reason why this approach won't work in a Wordpress site.
I need an email form that doesn't reload the contact page as the form is at the bottom.
html
<form action="#" id="contact_form">
<input type="text" id="name" placeholder="Name:">
<input type="text" id="email" placeholder="Email:">
<textarea id="message" rows="8" cols="40" placeholder="Message:"></textarea>
<input type="submit" id="submit"/>
<div id="status">
<p></p>
</div>
</form>
Jquery
$('#submit').click(function(){
//
var nameVal = $('#contact_form #name').val();
var emailVal = $('#contact_form #email').val();
var messageVal = $('#contact_form #message').val();
//
$.post('/contact_form.php', {name: nameVal, email: emailVal, message: messageVal}, function(data){
$("#status p").html(data);
$("#status p").show().fadeOut(3500);
if(data.indexOf('Thank You')==0) {document.forms[0].reset();}
});
})
php
$errors = array();
$required_fields = array('name','email','message');
foreach($required_fields as $fieldname){
if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])){
$errors[] = $fieldname;
}
}
if(empty($errors)){
$name_field = Trim(stripslashes($_POST['name']));
$name = explode(' ', $name_field);
$firstname = ucfirst($name[0]);
$email_field = Trim(stripslashes($_POST['email']));
$message = Trim(stripslashes($_POST['message']));
//
$to = "info#ttmt.org.uk";
$subject = "Email from Website";
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
//
mail($to, $subject, $body);
echo "Thank You $firstname";
}else{
echo "Please complete all.";
}
--- UPDATE ---
I've got part of it working now.
Part of the problem was the jquery couldn't find the php.
I created a 'code' folder inside wp-conntent and put the php there and the jquery looks like this.
$j.post('wp-content/code/contactEngine.php', { theName:nameVal, theEmail:emailVal, theMessage:messageVal }, function(data){
Now I'm getting the returned data form the php file but the email isn't sent.
Will this not work in WP
mail($to, $subject, $body);
You cannot use $_POST['name'] within Wordpress. Using other namings for input fields will fix your issue, eventually you could use the 'Contact Form 7' Wordpress-plugin for a better user experience :-)

posting a footer contact form to a different script not working

I have two files the one which hosts my actual contact form and then a file where i post the form to.
contactform.php (which is part of the footer template)
<form id="contact" action="<?php bloginfo('template_url'); ?>/sendmail.php" method="post">
<label for="name">Your name: *</label>
<input type="text" id="nameinput" name="name" value=""/>
<label for="email">Your email: *</label>
<input type="text" id="emailinput" name="email" value=""/>
<label for="comment">Your message: *</label>
<textarea cols="20" rows="7" id="commentinput" name="comment"> </textarea><br />
</form>
sendmail.php
<?PHP
if(isset($_POST['submit'])) {
error_reporting(E_NOTICE);
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*#([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)
{
$to = preg_replace("([\r\n])", "", hexstr($_POST['receiver']));
$from = preg_replace("([\r\n])", "", $_POST['email']);
$subject = "Website contact message from ".$_POST['name'];
$message = $_POST['comment'];
$match = "/(bcc:|cc:|content\-type:)/i";
if (preg_match($match, $to) ||
preg_match($match, $from) ||
preg_match($match, $message)) {
die("Header injection detected.");
}
$headers = "From: ".$from."\r\n";
$headers .= "Reply-to: ".$from."\r\n";
if(wp_mail($to, $subject, $message, $headers,'',true))
{
echo 1; //SUCCESS
}
else {
echo 2; //FAILURE - server failure
}
}
else {
echo 3; //FAILURE - not valid email
}
}else{
die("Direct access not allowed!");
}
function hexstr($hexstr) {
$hexstr = str_replace(' ', '', $hexstr);
$hexstr = str_replace('\x', '', $hexstr);
$retstr = pack('H*', $hexstr);
return $retstr;
}
?>
The issue is that this does not know of wp_mail function. I know that I need to include something so wp_mail will be available but what do I add? The function does exist. The issue with including the file that has wp_mail defined is that inside that function it requires some core php functions (wp_mail is being overwritten by cimy_swift plugin)
hi why not try just submitting the form to the base wpurl? then within your header.php file copy and paste your code in?
ie: using a hidden field you can check to see if its been posts, in this case the hidden field is called 'action' and it has a value of 'sendemail'.
form
<form id="contact" action="<?php bloginfo('wpurl'); ?>" method="post">
//form stuff
<input type="hidden" name="action" value="sendemail" />
</form>
Header.php
within the header file we do a call to check and see if the form has been posted,
<html>
<head>
<title><?php wp_title();?></title>
<?php
if( isset($_POST['action']) && ($_POST['action']=='sendemail') ) {
// run your code
}
?>
</head>
if you dont want to go down that route, and wish to use your theme folder to hold the php script then what to is, include the below in your sendmail.php file
define('WP_USE_THEMES', FALSE);
require('../../../wp-blog-header.php');
//above is assuming your file is located in the theme root, not a sub folder.
this will give you access to all the wordpress functions and shortcodes etc..etc..
hope that helps a little..
Marty

Resources