Set a default value with angular js - angularjs

I have an field where the id is set via php:
<input name="user_id" type="text" value="<?php echo $this->r->user_id; ?>" ng-model="entry.user_id" >
But the value does not appear in the field.
How can I set it from php to angular js?

Set the initial value of the ng-model using ng-init instead:
<input name="user_id" type="text" ng-model="entry.user_id" ng-init="entry.user_id = <?php echo $this->r->user_id; ?>" >
I'm not sure about the php syntax, but this will set value for you as long as the controller has an entry object available.

<input type="text" ng-model="enquiry.companyName" ng-init="enquiry.companyName='<?php echo $_SESSION['COMPANYNAME'] ?>'" name="companyName">
Sigle quote around php block is important.

You might want to try ng-value as well. Might fit your situation better. I didn't come across it until today:
<input name="user_id" type="text" ng-value="<?php echo $this->r->user_id; ?>" ng-model="entry.user_id" >

Related

AngularJS Input Date field

I have a form for a user to update his/her information. One of the fields is for their Date of Birth (DOB) that it is autopopulated from the database.
The problem is that if the user doesn't need to update the DOB and since the DOB is a required field the form validation thinks that it is blank and it forces to user to interact or update the field.
This is the current code:
<input type="date" name="dob" ng-model="profileData.dob" class="form-control" value="<?php echo $row["dob"]; ?>" ng-init="profileData.dob='<?php echo $row["dob"]; ?>'" />
So what I did is that I updated the code by adding ng-change. This will allow the form to be submitted. The problem with this is that if the user really needs to update the DOB it will not update. It will keep whatever is showing in the field value:
<input type="date" name="dob" ng-model="profileData.dob" class="form-control" value="<?php echo $row["dob"]; ?>" ng-init="profileData.dob='<?php echo $row["dob"]; ?>'" ng-change="profileData.dob='<?php echo $row["dob"]; ?>'" />
How do I change the input date field so that it works correctly when it doesn't need to be updated and also works well when it needs to be updated?
Thank you in advance.
I solved in a very simple way:
HTML:
<input type="date" id="dob" name="dob" ng-model="profileData.dob" class="form-control" ng-init="profileData.dob" />
Js:
$scope.profileData = {
dob: new Date('<?php echo $row["dob"]; ?>')
};

Can i use an expression from ctrl in default input value in angularjs?

Can i use an expression from controller $scope in default input value in angularjs?
i mean something like this.
<input name="somename" id="someid" type="hidden" ng-model="tempmodel" ng-init="tempmodel={{ datafromcontroller.field }}">
i need a hidden input field with some default data. In a plain html with php would be something like..
<input name="somename" id="someid" type="hidden" value="<?php $var ?>">
Thank u and sorry for my english xD
I tried this and works!
<input name="somename" id="someid" type="hidden" ng-model=datafromcontroller.field>

Passing SESSION variable into angularjs textbox value

Is it possible to pass the userID from the session to the AngularJS textbox value? I have tried to put the echo call into the value="" but it doesn't work.
<input type="text" data-ng-model="user" id="user"
value="<?php echo $user; ?>" disabled/>
<button data-ng-click="add(userID)">Add</button>
You can not use php variable in angular template. As this template is render by angular engine so it will interpolate only scope variables. Use services for your data to get it from php and use it through your controller.
Ref - Take a look

cakephp 2.0 integration with paypal

Hello everyone,
I am new to paypal but now the basics of cakephp, rightnow I am making a paypal integration with cakephp but unable to pass the value to the paypal. I'm showing you my code. Please tell me if I'm doing something wrong.
function paypal()
{
if($this->request->is('post'))
{
echo $item_name_1=$this->request->data['Choose']['item_name_1'];
echo"<br>";
echo $amount_1=$this->request->data['Choose']['amount_1'];echo"<br>";
echo $item_name_2=$this->request->data['Choose']['item_name_2'];echo"<br>";
echo $amount_2=$this->request->data['Choose']['amount_2'];echo"<br>";
echo $cmd=$this->request->data['Choose']['cmd'];echo"<br>";
echo $business=$this->request->data['Choose']['business'];echo"<br>";
echo $upload=$this->request->data['Choose']['upload'];echo"<br>";
echo $currency_code=$this->request->data['Choose']['currency_code'];echo"<br>";
echo $item_number_1=$this->request->data['Choose']['item_number_1'];echo"<br>";
echo $item_number_2=$this->request->data['Choose']['item_number_2'];echo"<br>";
$this->redirect('https://www.paypal.com/cgi-bin/webscr?cmd='.$cmd.'&upload='.$upload.'&business='.$business.
'&currency_code='.$currency_code.'&item_number_1='.$item_number_1.'&item_name_1='.$item_name_1.
'&'.'amount_1='.$amount_1.'&item_number_2='.$item_number_2.'&item_name_2='.$item_name_2.'&'.'amount_2='.$amount_2);
}
}
I'm passing all the view values(including hidden fields) to my controller(all values are displaying correctly) and redirecting it to the paypal site. Here I'm sending multiple values but I'm getting error like this:
This recipient is currently unable to receive money.
If i write the same code in corephp then values are reaching to the paypal and everything working fine, please tell me where I'm getting wrong.
First off, you should prepare your code in the Controller:
function paypal(){
$this->set('paypalData', $this->request->data['Choose']);
}
... and then create a form (in a view) which is POSTed to the PayPal site:
//file: Views/ControllerName/paypal.ctp
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $paypalData['business']; ?>">
<input type="hidden" name="amount" value="<?php echo $paypalData['business']; ?>">
<input type="hidden" name="item_name_1" value="<?php echo $paypalData['item_name_1']; ?>">
<input type="hidden" name="item_number_1" value="<?php echo $paypalData['item_number_1']; ?>">
<input type="hidden" name="amount_1" value="<?php echo $paypalData['amount_1']; ?>">
<input type="hidden" name="currency_code" value="<?php echo $paypalData['currency_code']; ?>">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
The user would then click the button to go to PayPal, which is more reliable (and right :D). The url which you are redirecting to might fail in many ways, since your values are not url_encoded, might get too long, etc..
Second: Your error is probably popping up because you are using www.paypal.com instead of www.sandbox.paypal.com
Third: I copied the HTML above to ease the viewing, you should be using the Form helper inside the view to ensure proper HTML formatting.
Fourth: ECHOing inside a Controller action is just wrong. Especially so, if you are redirecting after making output. Redirects will not work if any output is sent to the browser.
Hope this gets you in the right direction.

Formhelper to add a line Break in cakephp

The Form helper in cakephp
echo $form->input('Firstname', array('class'=>'test','name'=>'Firstname','type'=>'text'));
generates me like the following
<div class="input text">
<label for="Firstname">Frrstname</label>
<input type="text" id="Firstname" value="" class="test" name="Firstname"/>
</div>
is it possible to add a Break between label and input within the DIV .. If so how .. please suggest
I would suggest not adding the break.
Just use css:
label{display:block}
would achieve the same result.
echo $form->input('Firstname', array( 'between'=>'<br />','class'=>'test','name'=>'Firstname','type'=>'text'));

Resources