Need simple php help, but I don't really know php yet - php

<div class='rate-results'>
<div class='button-container'>
<input type='submit' id='btn-calculate' class='pure-button pure-button-primary' value='{$a['label_button_continue']}'></input>
</div><div class='rate-container'>
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
<div id='calculated_rate'>{$a['default_price']}</div>
</div>
how can i apply a link to this button?
['label_calculated_rate']
seems to pull the text
"GET A QUOTE"
from code up above it, but nowhere can i find how to turn this button into a link. The mentioned above code is as follows...
static function handle_shortcode($atts){
self::$add_script = true;
self::$add_styles = true;
$a = shortcode_atts( array(
'title' => 'Get a FREE Price Estimate',
'label_days' => 'Total days of coverage needed?',
'units_days' => 'days',
'label_attendance' => 'Estimated daily attendance?',
'units_attendance' => 'people',
'label_event_type' => 'What type of event is it?',
'label_sample_certificate' => 'View sample certificate',
'link_sample_certificate' => '#',
'label_button_continue' => 'Get Free Quote',
'label_calculated_rate' => 'Estimated Cost',
'default_price' => '$ 95.95',
'form_action' => 'javascript:void(0);',
'default_event_type' => ""
), $atts);
return "<form action='{$a['form_action']}' id='main_calculator' class='pure-form pure-form-aligned' data-default-event-type='{$a['default_event_type']}'>
<h3 class='title'>{$a['title']}</h3>

Replace
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
with
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
Replace http://www.w3schools.com/html/ with where you want the button to link to.
Hence adding a link to the button:
['label_calculated_rate']

Related

Drupal 7 customize user registration form

I am new to drupal.
I need to customize a registration form by adding fields like id,mobile etc.
Can I accomplish this by creating a custom module?
If yes could anyone please help me with a brief idea on creating and overriding the default user registration submit function. I have to insert these details to another table and also have to pass the data as a service request.
Ive created a custom module with function
module_form_alter(&$form,&$form_state,$form_id){
$form['#submit'] = 'module_form_submit';
if($form_id == 'user_register_form'){
//print_r($form_id);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('id'),
'#default_value' => '',
'#size' => 60,
'#maxlength' => 15,
'#required' => TRUE,
);
}
}
function module_form_submit($form, &$form_state){
echo "test";
exit();
}
module_form_alter is being called and I can see the new field on the registration screen but the submit function is still not called. I need to override the default drupal register submit.
I already have the following function in my theme template.php
function templatename_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'portal_preprocess_user_login'
),
);
$items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-register-form',
'preprocess functions' => array(
'portal_preprocess_user_register_form'
),
);
$items['user_pass'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-pass',
'preprocess functions' => array(
'portal_preprocess_user_pass'
),
);
return $items;
}
user-register-form.tpl.php
<div class="form-group">
<?php print drupal_render_children($form); ?>
</div>
And page--user--register.tpl.php with the html
<div id="login-page">
<div class="container">
<div class="form-login" >
<h2 class="form-login-heading"><img src="<?php echo drupal_get_path('theme', 'portal') . '/images/logo.png'; ?>" width="100"><?php echo $createaccount; ?></h2>
<div class="login-wrap">
<?php
$elements = drupal_get_form("user_register_form");
$form = drupal_render($elements);
echo $form ?>
<?php if ($messages):?>
<div id="messages-console" class="clearfix">
<div class="grid_12">
<div class="mt-grid-fix">
<?php print $messages; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
Is this approach fine or should I change this approach inorder to make my custom module functional?
You can go to:
admin/config/people/accounts/fields
and add the fields that you need.
In the fieldset "User settings" don't forget check "Display on user registration form."

fread / fgets - How do I make php read links

I'm trying to make a php site read from a text file by using this:
<html>
<head>
<title>This is a test!</title>
</head>
<body>
<?php
$f = fopen("testfile.txt", "r");
// Read line by line until end of file
while(!feof($f)) {
echo fgets($f) . "<br />";
}
fclose($f);
?>
</body>
</html>
-and it works!
Next step is to make the php site read text with links inside.
This is the text in the text file within a link, please press this link www.stackoverflow.com and more text to come after the link. Linktext like "THIS IS A LINK" is also needed.
Hope you understand what I want:)
How do I do something like this?
From reading your: "I want seperate text files for the different text sections on the site."
Have you considered using a separate php file "setting.php" and inside making a multidimensional array with all the things you need?
<?php
$settings = array(
'header_text' => array(
'text' => 'This is my header text and it containts a link click here',
'color' => '#000000',
'font-size' => '12px'
),
'footer_text' => array(
'text' => 'Copyright © Terms and Conditions',
'color' => '#000000',
'font-size' => '12px'
),
);
?>
and if you need to go a step deeper and do it PER page:
<?php
$settings = array(
'index.php' => array(
'header_text' => array(
'text' => 'This is my header text and it containts a link click here',
'color' => '#000000',
'font-size' => '12px'
),
'footer_text' => array(
'text' => 'Copyright © Terms and Conditions',
'color' => '#000000',
'font-size' => '12px'
)
),
'about.php' => array(
'header_text' => array(
'text' => 'This is my header text and it\'s only for the about page and it containts a link click here',
'color' => '#000000',
'font-size' => '12px'
),
'footer_text' => array(
'text' => 'Copyright © Terms and Conditions and go to the main index page',
'color' => '#000000',
'font-size' => '12px'
)
),
);
?>
you can then include this file in your main script
include('settings.php');
and then call upon the array and such, all you do it edit the php file, and any changes would update.
This way you can manually edit any details you want!
Example:
<?php include('settings.php'); $curr_page = basename($_SERVER['PHP_SELF']); ?>
<div style="color: <?php echo $settings['header_text']['color']?>"><?php echo $settings[$curr_page]['header_text']['text']?></div>
<div style="color: <?php echo $settings[$curr_page]['header_text']['color']?>"><?php echo $settings[$curr_page]['header_text']['text']?></div>
Thanks for your great answer - it was easy to understand.
I need to make my php site read from a text file because it is my boss who needs to change text on the site, and I don't want him to delete any of the coding.
So, is there any way to make the php site read from a text file?
This is a text 1 (must be read from document 1)
This is another text (must be read from document 2)
This is another text section on the php and THESE WORDS shuld be a hyperlink in the middle of the sentence.
etc...
Thanks again!

setting Default Text inside Yii textarea

I'm new to Yii and i am facing issues with it. Hope some pros here can help me solve this. I bought a script online and i am editing it to my needs.
I want to have a text area with default texts. Example;
Name:
Age:
Sex:
what it is generating now:
<textarea class="span vertical medium" name="MAccount[accountInfo]" id="MAccount_accountInfo"></textarea>
what i want it to generate,or something like this :
<textarea class="span vertical medium" name="MAccount[accountInfo]" id="MAccount_accountInfo">Name: <br> Age: <br> Sex:</textarea>
something like above. But i only able to produce a textarea with blank/no content.below is my code,it is located inside a worklet.;
public function properties() {
$properties = array(
'elements' => array(
'accountInfo' => array(
'type' => 'textarea',
'class' => 'span vertical medium',
),
'email' => array(
'disabled' => true,
'append' => $this->model()->role == 'unverified' ? $this->t('unverified') : $this->t('verified'),
'hint' => $this->model()->role == 'unverified' ? $this->resendBtn() : '',
),
wm()->get('project.edit.buttons', array('step' => $this->step, 'projectId' => $this->project->id))->render('tools', array(), true),
),
'model' => $this->model(),
'class' => 'projectEditForm',
);
return $properties;
}
Default values are set in your model, not in your view. So you have to look in your model/ directory and locate the right model there. There you can add
public $accountInfo = "Name:\nAge:\nSex:";
<?php echo CHtml::activeTextArea($form,'abc',array('value'=>"12"));?>
$form->abc="Your text goes here"
it may help you

Checkboxes not showing for Drupal form

I am trying to get a Drupal form to show checkboxes, but I seem to be having no luck.
function multi_reg_pagecreate() {
$multi_reg_checkbox = multi_reg_checkbox();
print_r($multi_reg_checkbox);
$form['multi_reg_checkbox'] = array(
'#type' => 'checkboxes',
'#options' => $multi_reg_checkbox,
'#description' => t('Register for multiple events here')
);
return $form;
}
The data is in this format:
Array ( [22] => Test Event Reg [23] => Test Event Reg 2 )
Which seems similar to what is said in the example:
https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/6#checkbox
What am I not doing right?
EDIT:
I'm seeing this on the page displayed:
<form id="multi-reg-pagecreate" accept-charset="UTF-8" method="post" action="/domain/multiple-registration">
<div>
<div class="form-item form-type-checkboxes form-item-multi-reg-checkbox">
<label for="edit-multi-reg-checkbox">Events </label>
<div id="edit-multi-reg-checkbox" class="form-checkboxes"></div>
<div class="description">Register for multiple events here</div>
</div>
<input type="hidden" value="form-t_KSPV9ULp71yMEUHCtDUKV4R3M18M4ie2_M6cj-ZVU" name="form_build_id">
<input type="hidden" value="RzzEFjyCz29CjH9F9PAB5UV9Xq9VBCx8mTY_HppLfiA" name="form_token">
<input type="hidden" value="multi_reg_pagecreate" name="form_id">
</div>
</form>
function multi_reg_pagecreate($form, &$form_state) {
$multi_reg_checkbox = multi_reg_checkbox();
$form['multi_reg_checkbox'] = array(
'#title' => t('Events'),
'#type' => 'checkboxes',
'#options' => $multi_reg_checkbox,
'#description' => t('Register for multiple events here')
);
return $form;
}
EDIT:
Options has to look like:
'#options' => array (
0 => t('Monday'),
1 => t('Tuesday'),
2 => t('Wednesday'),
3 => t('Thursday'),
4 => t('Friday'),
5 => t('Saturday'),
6 => t('Sunday'),
),
or:
'#options' => drupal_map_assoc(
array(0,1,2,3,4,5,6)
),
... looks like:
Please post your screen from your current devel output of $multi_reg_checkbox
I know this question is old... but... how are you calling the form? Are you doing it from a hook_menu? If so: did you make sure to put
'page callback' => 'drupal_get_form',
'page arguments' => array('multi_reg_pagecreate'),

Why drupal_render($form) does not render correctly RADIOS #type?

I'm trying to use drupal_render() to render a single form element. I can successfully render elements of '#type' => 'textfield' or 'radio' or 'whatever'.
When I try to render an element of '#type' => 'radios' something goes wrong. I can't find out why but the radios simple won't show.
$options = array(
'0' => 'no option',
'1' => 'option 1',
'2' => 'option 2',
'3' => 'option 3',
'4' => 'option 4',
'5' => 'option 5'
);
$form['radiosinput'] = array(
'#type' => 'radios',
'#title' => 'radios title',
'#description' => 'radios description',
'#default_value' => 0,
'#options' => $options,
'#required' => TRUE,
);
var_dump( drupal_render($form) );
// string(257) "<div class="form-item">
// <label>radios title: <span class="form-required" title="This field is required.">*</span></label>
// <div class="form-radios"></div>
// <div class="description">radios description</div>
// </div>
// "
Anyone knows what's the problem and the fix/workaround?
Is there any known problem with rendering radios or something?
Thanks!
You can't render form elements without a form because the the radios element has a process callback of form_process_radios() that is called only when used with the form API.
You might be able to try something like:
$form['radiosinput'] = expand_radios($form['radiosinput']);
return drupal_render($form);
For D7 use form_process_checkboxes()
I was working on something similar an hour ago. Your code pasted into my form works just fine.
Try
drupal_get_form('your_form_id');
Does that work?
I had the same trouble with the checkboxes element I wanted to render in a table. I found your answer a little bit to late.
So for all other searching how to render a checkboxes element with drupal_render and expand_checkboxes:
$form['test'] = array(
'#type' => 'checkboxes',
'#title' => t('Test'),
'#description' => t('The description appears usually below the checkboxes.'),
'#options' => array(1,2,3,4),
);
drupal_render(expand_checkboxes($form['test']));
I might add, that in D6 you need to add #parents => array() to the radios element.
if no, expand_radios will throw an error, in my case. Drupal 6.22

Categories