Good afternoon,
I'm now use the Registration plugin of Facebook and I would to set the default value of a field in text type.
But I don't know if it's possible ? How to set a default value of a text field in PHP and in the plugin ? Thank's for your Help !
<iframe src="https://www.facebook.com/plugins/registration?
client_id=APP_ID&
redirect_uri=[...]&
fields=[{'name':'name'},
{'name':'last_name'},
{'name':'first_name'},
{'name':'birthday'},
{'name':'gender'},
{'name':'email'},
{'name':'telephone', 'description':'T\u00e9l\u00e9phone', 'type':'text', 'default':'sith'},
{'name':'portable', 'description':'Portable (facultatif)', 'type':'text','no_submit':true},
{'name':'fax', 'description':'Fax (facultatif)', 'type':'text','no_submit':true},
{'name':'adresse','description':'Adresse','type':'text','default':'truc'},
{'name':'adresse_suite','description':'Adresse (suite)','type':'text','no_submit':true},
{'name':'code_postal','description':'Code postal','type':'text'},
{'name':'ville','description':'Ville','type':'text'},
{'name':'pays','description':'Pays','type':'select',
'options':[...]},
{'name':'password'},
{'name':'captcha'},
{'name':'abonnement','description':'Re\u00e7evoir la Newsletter','type':'checkbox'},
{'name':'stop_pub','description':'Re\u00e7evoir des offres marketing et bons d\'achat','type':'checkbox'},
{'name':'offre_sortir','description':'Re\u00e7evoir des bons plans Sortir Malin dans votre r\u00e9gion','type':'checkbox'},
{'name':'offre_partenaire','description':'Offres publicitaires de la part d\'autres partenaires','type':'checkbox'}]"
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="100%"
height="850"
onvalidate="validate">
</iframe>
Sorry for my bad English, I'm French ! =)
According to the documentation, the default parameter is only applicable to the type:select and type:checkbox fields, not the text fields ): So you're kinda screwed there.
For reference:
default only applies to select and checkbox fields http://o7.no/K5jDj0
However, if it were me, I'd build a complete array of the options I wanted to send, and json_encode them in one go instead of defining them directly inside the <iframe> tag, for example:
<?php
$regOptions = array(
array('name' => 'name'),
array('name' => 'last_name'),
array('name' => 'birthday'),
//the other fields
array('name' => 'telephone',
'description' => 'T\u00e9l\u00e9phone',
'type' => 'text'
),
//the other fields
);
?>
//Then in your iframe:
<iframe src="https://www.facebook.com/plugins/registration?
client_id=APP_ID&
redirect_uri=[...]&
fields="<?= urlencode(json_encode($regOptiosn)); ?>
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="100%"
height="850"
onvalidate="validate">
</iframe>
This allows you to leverage json_encode and urlencode to define your fields without fear of the browser mucking up the request due to wonky strings.
As for some fields being optional, required, check out the advaned registration button features in the doucmentation. FB affords you a few ways to validate your form, which should allow you to block form submission when fields are invalid/not filled out.
Related
I have a custom module called "visionart cart" working as expected and have enabled a page through hook_menu();
function visionart_cart_menu(){
/**
* Implements hook_menu()
*/
$items['build-order'] = array (
'title' => 'Build your order',
'menu_name' => 'main-menu',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'visionart_cart_build_order',
'access arguments' => array ('access content'),
'access callback' => 'user_is_logged_in',
);
}
Page callback returns the template page, everything works:
function visionart_cart_build_order() {
return theme('build_order_template');
}
/** Implements hook_theme. */
function visionart_cart_theme() {
return array (
'build_order_template' => array (
'template' => 'build_order'
)
);
}
In build_order.tpl.php, I've added a bunch of custom HTML show up on the build_order.php page. Everything renders fine. But I'd like to add user autocomplete functionality to the input field that is created on this build_order.tpl.php file.
<li class="my-custom-item">
<input type="text" name="build_order_username" value="" />
</li>
How and where do I do that? I've seen how to create form fields programmatically through Drupal's form building functions, but i can't find where to indicate to Drupal that this custom created input should use autocomplete on the user base. Thanks!
You will require an API endpoint call, which will auto-complete the fields. Assuming you are on Drupal 7, here is a link from the official Drupal documentation on how to make autocomplete fields.
I'm developing a website using cakephp 2.x.
Now, I create a form using Cakedc/search. This form has input(select/dropdown list).
But the list is too long, so I want the dropdown to be view as unordered list (< ul >< li >).
Like in the lazada (search for brand): http://www.lazada.com.my/womens-watches-bags-accessories/.
the code:
<?php echo $this->Form->create('Product', array(
'url' => array_merge(array('action' => 'search'), $this->params['pass'])));
echo $this->Form->input('brand_id', array('label' => 'Brand', 'options' => $brands, 'empty' => 'Select Brand'));
<?php echo $this->Form->submit(__('Search', true), array('div' => false));
echo $this->Form->end();
?>
Please someone help me. Thanks in advance..
You'll have to use javascript to get the id of the clicked li element or the link inside, use data attributes for that for example. Then set this value to a hidden form field or directly submit the whole form using ajax to update your results.
Your example URL is a simple list by the way that is just doing redirect on click.
How can I use an image button instead of the text in the following code
JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details'))
in HTML it is rendering as <a href="blah blah">Product details
How to use the image instead of Product details in HREF tag in above php code
JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details'))
$product is a PHP object, and JHTML is used by joomla! framework to output links
Actually your code:
JHTML::link ($product->link, JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name, 'class' => 'product-details'))
is equal to plain HTML
<?php JText::_ ('COM_VIRTUEMART_PRODUCT_DETAILS');?>
JText is used to output words and phrases based in a language INI file based in language/LANGUAGE_ID/folder. For english language and virtuemart component your string is located in /language/en-GB/en-GB.com_virtuemart.ini
in order to use an image link try
<img=src="myimage.png" />
Let's say I have a Zend_Form form that has a few text fields, e.g:
$form = new Zend_Form();
$form->addElement('text', 'name', array(
'required' => true,
'isArray' => true,
'filters' => array( /* ... */ ),
'validators' => array( /* ... */ ),
));
$form->addElement('text', 'surname', array(
'required' => true,
'isArray' => true,
'filters' => array( /* ... */ ),
'validators' => array( /* ... */ ),
));
After rendering it I have following HTML markup (simplified):
<div id="people">
<div class="person">
<input type="text" name="name[]" />
<input type="text" name="surname[]" />
</div>
</div>
Now I want to have the ability to add as many people as I want. I create a "+" button that in Javascript appends next div.person to the container. Before I submit the form, I have for example 5 names and 5 surnames, posted to the server as arrays. Everything is fine unless somebody puts the value in the field that does not validate. Then the whole form validation fails and when I want to display the form again (with errors) I see the PHP Warning:
htmlspecialchars() expects parameter 1 to be string, array given
Which is more or less described in ticket: http://framework.zend.com/issues/browse/ZF-8112
However, I came up with a not-very-elegant solution. What I wanted to achieve:
have all fields and values rendered again in the view
have error messages only next to the fields that contained bad values
Here is my solution (view script):
<div id="people">
<?php
$names = $form->name->getValue(); // will have an array here if the form were submitted
$surnames= $form->surname->getValue();
// only if the form were submitted we need to validate fields' values
// and display errors next to them; otherwise when user enter the page
// and render the form for the first time - he would see Required validator
// errors
$needsValidation = is_array($names) || is_array($surnames);
// print empty fields when the form is displayed the first time
if(!is_array($names))$names= array('');
if(!is_array($surnames))$surnames= array('');
// display all fields!
foreach($names as $index => $name):
$surname = $surnames[$index];
// validate value if needed
if($needsValidation){
$form->name->isValid($name);
$form->surname->isValid($surname);
}
?>
<div class="person">
<?=$form->name->setValue($name); // display field with error if did not pass the validation ?>
<?=$form->surname->setValue($surname);?>
</div>
<?php endforeach; ?>
</div>
The code work, but I want to know if there is an appropriate, more comfortable way to do this? I often hit this problem when there is a need for a more dynamic - multivalue forms and have not find better solution for a long time.
Having no better idea, I have created a view helper that handles the logic presented above. It can be found here.
If the helper is available in the view, it can be used in the following way (with the form from the question):
<?=
$this->formArrayElements(
array($form->name, $form->surname),
'partials/name_surname.phtml'
);
?>
The contents of the application/views/partials/name_surname.phtml partial view are:
<div class="person">
<?= $this->name ?>
<?= $this->surname ?>
</div>
The fields are rendered according to the posted form and validation messages are shown only next to the values that failed validation.
The helper's code is far from perfect (I just rewrote the idea from the question) but is easy to use and can be considered as good starting point.
I have a product search page with the form below. The search result is displayed on the same page with search bar at the top.
echo $this->Form->create('Searches', array('action'=>'products', 'type' => 'get', 'name' => 'textbox1'));
echo $form->input($varName1, array('label' => false));
echo $form->end('Locate');
I also have a little box next to the search result that allows (it doesn't work yet) the user to flag using checkboxes a product and accordingly update its database (table products and using model Product) with a button click. Note that I have a Searches controller for this search page.
<form method="link" action="/myapp/product/test_update_db>
<label><input type="checkbox" name="flag1" <?php echo $preCheckBox1; ?>>Flag 1</input></label>
<label><input type="checkbox" name="flag2" <?php echo $preCheckBox2; ?>>Flag 2</input></label>
<input type="submit" value="Update">
</form>
I'm having difficulty with this approach figuring out how to perform this check-box-and-DB-update routine. I'm getting to the link I'd like to go (/myapp/product/test_update_db), but I don't know how to take variables flag1 and flag2, along with row ID of this result ($results['Product']['id'])) to the new page.
Could someone guide me on how to perform this neatly? Is this general approach correct? If not, what route should I be taking? I'd prefer not to use javascript at this time, if possible.
EDIT: I think I can make this work if I use the URL for passing data.. but I'd still like to know how this could be done "under the hood" or in MVC. I feel like I'm hacking at the CakePHP platform.
UPDATE: So, I ended up using the URL parameters for retrieving information pieces like flag1 and flag2. I'm still looking for an alternative method.
To see where your is-checkbox-checked data is located, do the following in your controller:
// Cake 2.0+
debug($this->request->data);
// previous versions
debug($this->data);
If you want to pass data to your search controller from the current page, you can always add the data to your form:
$this->input
(
'Product.id',
array
(
'type' => 'hidden',
'value' => $yourProductId
)
);
I ended up using information embedded in the URL for getting submission data. Something like below..
In Products controller, when the form with flag1 and flag2 are submitted:
public function test_update_db() {
// Get variables from URL, if any, and save accordingly
$result = $this->Product->updateProduct($this->params['url'], 'url');
if ($result) {
$this->Session->setFlash('Successfully updated!', 'default', array('class' => 'success'));
$this->redirect($this->referer());
}
else {
$this->Session->setFlash('Update was unsuccessful!', 'default', array('class' => 'error'));
$this->redirect($this->referer());
}
}
This works for doing what I needed to do. I feel like there's a more proper way to do this though.
if ($result) {
$this->Session->setFlash('Successfully updated!', 'default', array('class' => 'success'));
$this->redirect($this->referer());
}