In Views, when I rewrite a field and then hide some other fields and use their tokens to compile them into that first one I rewrite, how would I go about doing an operation such as this:
Example:
Say I have these fields:
field_first_name
field_last_name
field_old_nickname
field_new_nickname
Everyone has a first & last name, but:
Some people have ONLY an old nickname
Some people have ONLY a new nickname
Some people have both an old & new nickname
What if I want to rewrite these fields into a format such as "John (Nobody) Doe?"
Normally, we would hide all fields but the first name and do this:
[field_first_name] ([field_new_nickname]) [field_last_name]
But what if John has a old nickname too and we want to display the old one instead if that's the case?
Get what I'm saying?
Thanks in advance.
You can use the option "exclude from display if empty" for the
two fields "field_new_nickname" and "field_old_nickname"
then rewrite the output field as : [field_first_name]
([field_new_nickname] ,[field_old_nickname]) [field_last_name]
so the empty field will not show up
A #drupal-support IRC user named "ciss" answered this question for me-- it was much easier than I had thought, which is great. Thank you ciss!:
"Regarding your tokens question: you can use tokens in the empty output of a field. That way you can trigger which tokens should get displayed. Make sure you pick a field for rewriting that can actually be empty (either empty string or "0"). if necessary, add a specific field twice-- Views will not check if the rewritten content is empty."
Related
Is there a way to call field rows in a URL without using the column name??
So I currently have a posting site where users can select category or subcategories of choice from drop downs, how it's currently setup my site outputs links to the categories chosen such as..
topics.php?category=Food&sub_cat=Pies
topics.php?sub_cat=Pies
This allows users to go to either one of the links, or both
topics.php?category=Food&sub_cat=Pies
To give more functionality I am looking at adding textboxes instead of drop downs, the problem is users will more than likely enter the data in different boxes than other users, ie.
User 1. catbox: Food subcatbox: Pies
User 2. catbox: Pies subcatbox: Food
So in this case my current URL system won't return accurate results, so my question is would there be a way where "category" or "subcategory" could be replaced and just put the results together without them being listed in 2-5 different fields therefore not returning all the results that = to that value? "food" or "pie" in this example.
topics.php?xxx=Food&xxx=Pies
or
topics.php?xxx=Pies&xxx=Food
Looking at So homepage if you click "php" it will put php in the URL, click mysql and it will put "php+mysql" that sort of thing.
you can use parent child method in your database.your table would be like this
id - parent_id - category_name - depth
when you want to insert a data to your table it's depth will be one plus it's parent depth
when someone post to your page you first take query witch of the inputs has most depth then that will be your subcategory.
Calling field rows via parameters in your URL may be a very bad idea. It's a perfect way to allow a massive SQL injection attack. So, the answer is probably "yes, but HOLY MOLY PLEASE DON'T!"
Now it may be that your code is parsing these out on the back end and protecting them via any of a variety of methods, I can't tell from the amount of code posted.
The problem is :
There are two pages , one for editing name records and one for adding name records.
If I first open an edit page,then I open an add page , and input a name in add page
before I submit the name, I use the edit page to change the name,
(say change from varChar to integer type)
,after that, return to add page and submit the name.
Should this cause an error? How can I prevent this error?
In most web applications that I have used, the first valid request to be processed wins. I think you need to clarify your question, though, as it doesn't sound like the situation you describe would be possible, or it would not be a problem.
It sounds like NAME is a field in a record, not an entire record on its own. It doesn't seem like you could change the NAME field and add it at the same time. Let's imagine you have a record type PERSON that is backed by a table in your database. Each PERSON record has a NAME field that is currently of varChar type. It sounds like you are using a web interface to edit the structure of this table.
If the table already has a field NAME, the add page submission will report an error because a field called NAME already exists. The edit page would succeed, assuming it is possible to convert the NAME field to the integer type: either there are no records, or the value of NAME in every record can be converted to an integer.
Another interpretation of your question is that you are changing the NAME field to be something else entirely in the edit screen, perhaps from NAME varChar to AGE integer. You also happen to use the add page to add a new NAME char(10), for example. This would be allowed as long as the edit page submission is processed before the add page submission.
In a web form i will ask the user for their job experiences, this data will have no fixed lenght. I need to let the user insert all the items he needs, every item will content 3 fields; job title, description and year.
My firts problem is, how can i ask in the html form for the items? i mean, whats the best way to ask items with no fixed lenght using html/php (and maybe ajax)? I saw some sites that have a button (add one) when you hit it a new item slot is showed, but i have no idea of how to implement this, an example will be sufficient.
The second part is, how can i managed the data flow in post or get?, until now, i only use fixed fields, so i always know in my php script how many post or get vars i will get. How can i use multiple POST vars without knowing the amount of them?
And the last one (and the more important), how will be the best structure for my table in MySQL? If i get multiple items for a fixed table where i will have all my users, how can i resolve the multiple items issue? For example, if my table is:
User | password | job_experiences
admin | root | (this is just a cell, how can i save multiple items here?)
jonh | 1234 | (this is just a cell, how can i save multiple items here?)
Thanks for any help!!!!
Those are 3 questions, and it's best to post 3 questions, instead of discussing all of them. I will post the basics, and if you have specific questions, ask.
First, use button to add, and a JavaScript to clone an existing row (which can have more then one input field). For fieldnames use something like company_name[] - the [] is the important part, at this will send the field as an array. If you are editting profile, you can use company_name[$id] to preserve the mapping.
Second, in PHP you will receive this as $_POST['company_name'] which will be numeric array with all the company names. Or if you specify $id - with the corresponding keys. So, you have to loop trough all company_names, if there are other fields - you retrieve them the same way, using the current key. Example:
for (i =0; i<$_POST['comany_name'].length;i++) {
$company = $_POST['comany_name'][$i];
$start_year = $_POST['from'][$i];
...
}
Next, you need 1 table for the users (username, password), and another for job experiences (userid, company, description, from, to). This is called 1:M relation
I am new in magento I would to validate my DOB fileds on the registratoin page so that valid dates can be inserted by the user, at the moment the input fieds accept anything and a user can input any number of text and it accepts can you guys please help?
Look in your theme's (or default) template/customer/form/widget/dob.phtml file. It creates three strings which describe the three text inputs for day, month and year. You can either add the validate-number name to their class or rewrite them to use <select> elements instead.
I have read other answers on this (or at least near to this) subject but I couldn't get a clear view of it so I'm asking for help again.
I have a complex dynamic HTML form that I would like to submit to database using PHP. The form is split into multiple tabs and in each tab I got checkboxes that trigger other parts of the form. Example: at a point in my form I got a checkbox group that has options of: "hotel" and "restaurant". If I check hotels, I get another part of the form displayed, specific for "hotels". Same thing for "restaurant". So it's very dynamic here and I don't know which would be the best approach for storing every form field in database. Because it could contain 15 fields or 20, depending on the selection. Any example would be appreciated as I'm not that advanced with database design.
Thank you!
So it's very dynamic here and I don't
know which would be the best approach
for storing every form field in
database.
I apologise if I have misunderstood you here but I believe that you should design the database according to the data and not the form. It is difficult to comment without knowing the exact details of your situation so here is an example:
If you usually dump all the data from a form into a single table, but because sometimes this will involve submitting 5 values and other times this will involve submitting 10 and so you are unsure how many columns your table should have, then I think the problem is in the database design.
Work out what pieces of data are dependent on other pieces of data. For example, you mention checking "hotel" might open up more fields specific to that choice. Let's assume this involves things like "en-suite", "bed type" etc. Then you should have 3 tables, a registration table (assuming the user is using the form to buy these services), a hotel table and a registration_hotel table. The registration table will record a number of details specific to the registration only such as the customer's name and a unique id number. The hotel table will hold information specific to the hotel only, such as how many rooms have en-suite. The registration_hotel table will hold details specific to that registration at that hotel. You might want a column of type bool to record whether the user requested "en-suite".
When submitting the form, check which pieces the user entered with if(isset($_POST['hotel']) && !empty($_POST['hotel'])). Then only send stuff to the registration_hotel table if that condition is true.
If this design results in making too many separate calls to the database, you might want to look into transactions which will help you to manage the speed and security of these calls.
If you can post in a specific example of something you don't know how to do, that would be useful.
You didn't specify how you can manage this dynamic form. Can you edit it's PHP/HTML source? One great thing would be if you can label your different variables like hotel[], restaurant[], etc.
If your submitted form is clear enough (i mean semantically correctly structured) you can store the whole submitted form serialized.
Note: this method only working when you don't need to search for specific items in your database.
Edit: maybe i'm misunderstood your problem.
You can create a 'metadata' table like this:
form_id | option_name | option_value
---------------------------------------
1 | hotel | true
1 | restaurant | false