Hi guys I'm building a contacts application using the Zend Framework 1. I have a contacts table and a contact_data table.
Contact
|NAME|DESCRIPTION|...
CONTACT DATA
|TYPE|LOCATION|DETAILS|CONTACT_ID
ADDRESS
STREET|ZIP|CITY|STATE|COUNTRY|CONTACT_ID
The Contact Data holds all contact details such as Phone, Email, Fax etc and the address table is self explanatory. The trick is that I need to set it up so that I can add unlimited contact data and addresses. I've accomplished this earlier on by pretty much working on customised views however thats putting a lot of code logic within the view which I don't want. So I'm redoing it using Zend_Form but am stuck with regards to setting up the add/edit/remove multiple contact details from the same form part.
I have the javascript worked out and know how to get it done using views - but I need to get this done using Zend Forms here. I've looked at the idea of subforms however in my case I need to do the following:
My form is stuctured as follows:
Text and INputs for all contact details listed out
A special contact Data region with links to Add a Phone, Add a Fax, Add an address. Clicking on these links would open up and add a set of inputs to the table eg add an address link adds a street, city, country and state set of input to the table.
I've been hacking at this for an hour and am pretty lost here. Any ideas on how can i handle this?
I think the best way to solve this problem is creating new Elements. One for contact data and one for address. Each of those elements should have custom viewHelper to render your complex interface. Each of view helpers can assign javascript file to handle dynamic adding / removing.
class Form_Element_Contact extends Zend_Form_Element_Xhtml {
public $helper = 'contact';
}
class Zend_View_Helper_Contact extends Zend_View_Helper_FormElement {
public function contact($name, $value = null, $attribs = null, $options = null) {
$this->view->headScript()->appendFile("/js/dynamicInterfaceForContacts.js");
$info = $this->_getInfo($name, $value, $attribs, $options);
$html = $this->generateHtml(); // elements should be part of an array
return $html;
}
}
If you need more details let me know.
Related
I'm using Laravel to create an online teaching system, I have a rudimentary CRUD system that allows me to create degree paths. When I click on a degree path I'm taken to degrees/{{ degree->id }} and from there I can create modules. When I submit my form however, I don't know how to redirect back to that specific view. I can redirect back to the index page, then access the view and see that the module has been added, but I don't know how to go straight to the degree view.
I'm aware you can manually input the ID, but then what if I wanted to create a module for another degree?
Anyway, here's the store function, where my data is submitted to :
public function store(Request $request)
{
$module = new Module;
$module->title = $request->input('title');
$module->description = $request->input('description');
$module->save();
return redirect('/degrees');
The issue is in the redirect, I need to know how that can transfer me to the route (degrees/{{ degree->id }}), but if I type that out it doesn't understand what ID I actually want and throws an error.
Any advice is welcome, the functionality works, I can see the modules displayed on the degree page just need to know how to get there after submitting the data.
I'm relatively new to web-dev, so if I need to re-do things feel free to tell me I'm probably compounding errors at this point.
try this:
return back()->with('success','Submitted successfully');
return redirect()->back()->with('success', "success message");
I am trying to create a function that matches user's that have the same expertise as a custom post custom field. So if a custom author meta has an expertise of 'Ninja' and the custom post type has a custom field that also has 'Ninja', my email will go out to all those matching user's.
I have the following bit of wp_mail code and can also create user queries using get_users but cannot get the two to work as i need. Any ideas?
add_action('future_to_publish', 'send_emails_on_new_event');
add_action('new_to_publish', 'send_emails_on_new_event');
add_action('draft_to_publish', 'send_emails_on_new_event');
add_action('auto-draft_to_publish', 'send_emails_on_new_event');
function send_emails_on_new_event($post) {
global $post;
$expertise = get_field('expertise', $postid);
$emails = MATCHING USER EMAIL ADDRESSES TO GO HERE;
$message = '<p>Email content will go here ...</p>';
if (get_post_type($post->ID) === 'custom_post_type') {
wp_mail($emails, "Email title will go here ...", $message);
}
}
Have you tried using SQL query actually to get matching emails from database??
something like
$sql = SELECT user.email FROM user WHERE user.expertise = $postExpertise;
$email = database->getRecords($sql); //getRecords() is just general function placeholder, build your own db processor class
...
function send_emails_on_new_event($post) {
...
}
You have to understand, WP is just a tool written in PHP with common functionality, if you want custom functionality, either build it yourself or if you are lucky, find plugin already created with similiar functionality. But you will not always find the plugin you want.
Hence why WP is good only for low-budget websites built by not so great web developers. Because if you can build custom functionality on top of WP, you should already consider if using WP is even good idea in first place
I'm a newbie to web designing. I'm using contact form 7 to create a registration form for our conference.
All I wanted to do is, I need to give a unique id for all of them after they have registered for the conference and the further forms should be identified using this unique id.
So far, I have installed contact form 7 and contact form dtx
for this purpose and I have tried Koen de Bakker solution of generating a random number.
But it's slightly different from what I want, since it changes the random number for each refresh.
What I'd like is:
An unique number like "17ICLAA001,..." should be generated for each form submission.
Send the unique number to the applicant after successive submission of the form.(I hope this can be easily done once the shortcode is done).
Editing the form using the unique id.
Any help will be much appreciated. Thank you.
I have found a way to do this. Its just the number of rows+1 in the table.
When you add a record to your table the unique number also gets increased by 1 in the following code. Add the following function in function.php in your theme and use the short code "row_count" to call the function. Use it with dynamichidden text from dtx.
function row_count_shortcode() {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->username_wp1.SaveContactForm7_1" )+1;
return "17ICLAA".sprintf('%03d',$user_count);
}
add_shortcode( 'row_count', 'row_count_shortcode' );
Usually when you are creating contact forms using contact form7 it automatically creates a table in your database something like
username_wp1.SaveContactForm7_1
Instead of this replace your database table name.
So in your contact form, type
[dynamichidden uniqueid "row_count"]
and use [uniqueid] in your email body to serve your purpose.
It works fine. I have checked in my site.
Correct way to generate a unique and progressive number is to set a field in wp_option like this:
add_option('unique_number', '1');
When filter is called, you must simply increment this unique number:
function genTicketString() {
$currentUniqueNumber = get_option('unique_number');
$newCurrentUniqueNumber = $currentUniqueNumber + 1;
update_option('unique_number' $newCurrentUniqueNumber );
return $newCurrentUniqueNumber;
}
add_shortcode('quoteticket', 'genTicketString');
Going a bit mad here... :)
I'm just trying to add CCK fields from a Content Profile content type into page-user.tpl.php (I'm creating a highly-themed user profile page).
There seem to be two methods, both of which have a unique disadvantage that I can't seem to overcome:
'$content profile' method.
$var = $content_profile->get_variables('profile');
print $var['field_last_name'][0]['safe'];
This is great, except I can't seem to pass the currently viewed user into $content_profile, and it therefore always shows the logged in user.
'$content profile load' method.
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
Fine, but now I can't access the full rendered fields, only the plain values (i.e. if the field has paragraphs they won't show up).
How can I have both things at once? In other words how can I show fields relating to the currently viewed user that are also rendered (the 'safe' format in 1)?
I've Googled and Googled and I just end up going round in circles. :(
Cheers,
James
Your content profile load method seems to be the closest to what you want.
In your example:
$account_id = arg(1);
$account = user_load($account_id);
$user_id = $account->uid;
$var = content_profile_load('profile', $user_id);
print $var->field_first_name[0]['value'];
The $var is just a node object. You can get the "full rendered fields" in a number of ways (assuming you mean your field with a filter applied).
The most important thing to check is that you're field is actually configured properly.
Go to:
admin/content/node-type/[node-type]/fields/field_[field-name] to configure your field and make sure that under text processing that you've got "Filtered text" selected.
If that doesn't fix it,try applying this:
content_view_field(content_fields("field_last_name"), $var, FALSE, FALSE)
(more info on this here: http://www.trevorsimonton.com/blog/cck-field-render-node-formatter-format-output-print-echo )
in place of this:
print $var->field_first_name[0]['value'];
if none of that helps... try out some of the things i've got on my blog about this very problem:
http://www.trevorsimonton.com/blog/print-filtered-text-body-input-format-text-processing-node-template-field-php-drupal
When you're creating a user profile page there is a built in mechanism for it. just create a user template file, user_profile.tpl.php.
When you use the built in mechanism you automatically get access to the $account object of the user you are browsing, including all user profile cck fields. You have the fields you are looking for without having to programmatically load the user.
I have a field called profile_bio and am able to spit out any mark up that is in without ever having to ask for the $account.
<?php if ($account->content[Profile][profile_bio]['#value']) print "<h3>Bio</h3>".$account->content[Profile][profile_bio]['#value']; ?>
I've tried themeing content profiles by displaying profile node fields through the userpage before and it always seems a little "hacky" to me. What I've grown quite fond of is simply going to the content profile settings page for that node type and setting the display to "Display the full content". This is fine and dandy except for the stupid markup like the node type name that content profile injects.
a solution for that is to add a preprocess function for the content profile template. one that will unset the $title and remove the node-type name that appears on the profile normally.
function mymodule_preprocess_content_profile_display_view(&$variables) {
if ($variables['type'] == 'nodetypename') {
unset($variables['title']);
}
}
A function similar to this should do the trick. Now to theme user profiles you can simply theme your profile nodes as normal.
Currently I'm trying to build a web application in Zend framework.
But I can't figure out how to Manage status in my system
Eg I have the following status for my quote handling in the system
Awaiting for Confirmation
Asssigned
In Progress
Completed
Mark As Spam
I stored these values in a table called ProviderQuoteStatus and I created a function called ProviderQuoteStatus() in the zend_db class and uses the function to generate status values in zend form dropdown box.
$select = $this->select()->from("providerQuoteStatus",
array('key' => 'providerQuoteStatusId',
'value' => 'providerQuoteStatusName'));
$result = $this->fetchAll($select);
return $result->toArray();
Here is my Zend form code
$serviceType = new Application_Model_DbTable_ProviderQuoteStatus();
$serviceTypeValues = $serviceType->getProviderQuoteStatusFormValues();
$dropDownElement = new Zend_Form_Element_Select('providerQuoteStatus');
$dropDownElement->addMultiOptions($serviceTypeValues);
Everything working fine till this stage. If the quote in Asssigned Stage I only wanted the provider select these following options
Asssigned
In Progress
Completed
How can I remove 'Awaiting for Confirmation' and 'Mark As Spam' values in the Zend form dropdown box ?
Also where should I stored all these business logic (For example if the quote in Assigned Stage only can have Assigned, In Progress options etc)? In the Model DB class?
Thanks so much in advance :D
You could populate the select element with all the possible options in $form-init(), as you are doing. But then modify the element during $form->setDefaults($defaults), at which point you will know the current value of the element and determine which options are no longer appropriate: if the element value is "Assigned", then remove the "Awaiting" and "Spam" options.