Populate form with customer data, if known - html

I am using Magento, and I have a form.html that asks for customer data. When the customer is logged in, I want to prepopulate the relevant fields with known data.
I have used the following constructs, but none work.
The listing begins with the (commented out) line that just asks for filling in, then my two modifications, the first one commented out. Both are not working. What's wrong?
<!--<td valign="top"><input maxlength="30" name="name" size="20" type="text"></td>-->
<!--<td valign="top"><echo Mage::getSingleton('customer/session')->getCustomer()->getName();></td>-->
<td valign="top">
<input type="text" name="name" value="<?php echo Mage::app()->getRequest()->getPost("name");?>" />
</td>

Your first modification (second line commented out) won't work because you haven't wrapped the PHP in its tags.
Try writing a statement to check if the customer is logged in.
<?php
if (Mage::getSingleton('customer/session')->isLoggedIn()) :
//Write out the customer's full name
echo Mage::getSingleton('customer/session')->getCustomer()->getName();
else :
echo 'Customer not logged in';
endif;
?>
If there is still no value being returned it might be because you haven't got the customer's session ID.

<?php
$customer = new Varien_Object();
if (Mage::getSingleton('customer/session')->isLoggedIn()){
$customer = Mage::getSingleton('customer/session')->getCustomer();
}
?>
<td valign="top">
<input type="text" name="name" value="<?php echo $customer->getData('name') ?>" />
</td>

Related

I am unable to find if the row already exists in mysql db using time function in php mysql query?

i am currently working on a module where faculty can post attendance to the students by selecting a dropdown(select box) which is generated dynamically by the information given by the faculty.When faculty selects a particular year and section respected student list is retrived and displayed in a table.But the requirement is once the attendance is posted to a particular class/section on a particular it cannot be opened again by the faculty
I have tried using mysql_num_rows() function to check if any rows are already present in the db or not on that particular date.But its not working the way i wanted
here is my entire code of the module excluding db file
<form action="take.php" method="Post">
<br>
<table class="table table-bordered table-hover ">
<tr>
<th>S.no</th>
<th>Student Name</th>
<th>Roll Number</th>
<th>Present</th>
<th>Absent</th>
</tr>
<?php
if (isset($_POST['search']))
{
$stu="Student";
$yr=$_POST['year'];
$se=$_POST['section'];
$subdr=mysql_query("SELECT subject FROM schedule WHERE id='$cuid' AND day='$d' AND class='$yr' AND section='$se'");
$subj=mysql_fetch_assoc($subdr);
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid' AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
$display=mysql_query("select name,id from login where role='$stu' AND academic='$yr' AND section='$se'");
$sno=0;
$count=0;
while ($row=mysql_fetch_array($display)) {
$sno++;
?>
<tr>
<td><?php echo $sno ?></td>
<td>
<?php echo $row['name'] ?>
<input type="hidden" name="name[]" value="<?php echo $row['name'] ?>">
</td>
<td>
<?php echo $row['id'] ?>
<input type="hidden" name="id[]" value="<?php echo $row['id'] ?>">
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Present" required>
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Absent" required>
</td>
</tr>
<?php
$count++;
}
}
?>
<tr>
<td colspan=5>
<center><label><?php echo "Subject : ".$subj['subject']; ?></label></center>
</td>
</tr>
<input type="hidden" name="yr" value="<?php echo $_POST['year']; ?>">
<input type="hidden" name="set" value="<?php echo $_POST['section']; ?>">
<?php
} ?>
</table>
<center><input type="submit" name="submit" value="Submit" class="btn btn-primary" >
</center>
</div>
the expected output should display a message saying "Records posted" based on query like :
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid'
AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
#display the student list
}
Your assignment is:
$dis_date=date("Y-m-d H:i:s");
so $dis_date contains both a date and a time of day. The query will only match if the records in the table have the exact same time of day, not just the same date.
You should leave the time out of the variable:
$dis_date=date("Y-m-d");
If the datatype of the column in the table is DATETIME, you also need to filter out the time from that, with:
AND DATE(ondate)='$dis_date' And subject='$subj_d'"
You don't need to do this if the datatype is DATE.

How to Display a custom value like customer number in order Email

I am working on a solution for the task to display a customer number in the order confirmation email.
There is already a custom attribute customer_number which is displayed in the register form and the customers back-end.
It seems to get displayed by calling a helper.
This is how it is displayed in the register form:
<input type="number"
name="<?php echo Company_Helper_Data :: CUSTOMER_NUMBER_FIELD ?>"
id="<?php echo Company_Helper_Data :: CUSTOMER_NUMBER_FIELD . "id" ?>"
value="<?php echo $this->escapeHtml($this->getFormData()->getData( Company_Helper_Data :: CUSTOMER_NUMBER_FIELD ) ) ?>"
title="<?php echo $this->__('Customer Number') ?>" class="input-text" />
This is how it gets called in the customer back-end
<input type="text"
name="customer_number"
id="customer_number"
value="<?php echo $this->getCustomer()->getCustomerNumber() ?>"
title="<?php echo $this->__(' Customer Number') ?>"
class="input-text" />
So I simply tried to put this code into the order/default.phmtl:
<?php echo $this->getCustomer()->getCustomerNumber()?>
Which does not work. The Order cannot be set.
I am rookie to programming. Does anyone has an idea how to call the customer-data in the order email-template and display it in the order confirmation?
For this in Magento, you'll have to go in magento backend admin panel,
next go to
system=>Transactional Emails
Here you'll find your email template.
After this open the email template and then place this where you would like
{{ var customer_number }}

html mailto not sending email

I am using a simple form to submit name email and phone number.
I want these details to be sent to an email id, but it is not sending
Someone please help.
<form action="MAILTO:xyz#gmail.com?name=name&email=email" method="post" enctype="text/plain">
<tr>
<td width="336" height="148" colspan="9">
<input type="text" name="name" style="width:336; height:40; padding-left:10px" placeholder="Name" required>
<img src="images/spacer.gif" width="336" height="14" alt="">
<input type="email" name="email" style="width:336; height:40; padding-left:10px" placeholder="Email Id" required>
<img src="images/spacer.gif" width="336" height="14" alt="">
<input type="tel" name="name" style="width:336; height:40; padding-left:10px" placeholder="Contact Number" required>
</td>
</tr>
<tr>
<td width="186" height="65" colspan="7">
<input type="submit" value="Submit" style="width:186; height:65; background-color:black; color:white;"></td>
</tr>
</tr>
</form>
The mailto: is not for sending emails, instead it will create a mail with the receiver email specified in the mailto:receiver#abc.com.
For e.g :
If you are having a windows PC and if you have Outlook as your default email software ,then clicking on the <a href="mailto:xyz#gmai.com"> will open up outlook with xyz#gmail.com in the to field.
If you want to send emails you can use PHP mail function to do it.
In the form action instead of mail to function add a PHP script file you have created and follow this code structure.
HTML :
<form method="post" action="your_php.php">
Receiver Email : <input type="text" name="to">
<input type="submit" value="sendMail">
</form>
your_php.php script :
<?php
$to = $_POST['to'];
//Getting the 'to' textbox data from the form
/* If you are using GET method ,then use $_GET[] */
$subject = "Your Mail Subject" ;
$message = "Your message to be sent" ;
$headers = "From: yourmailid#domain.com" ;
// If you leave the $headers from field empty,then your server mail ID will be displayed
and it may be moved to the spam section of the email
mail($to,$subject,$message,$headers);
/* Done , Your mail will be sent to the email address you want
?>
This will send the mail to the required email address.
P.S.
PHP is a server side scripting language ,So you cannot send the mail unless you have a hosting server for your webpage and php script.
mailto: is a scheme prefix to identify a link as an email address, opening the default email application for the client, i.e. you shouldn't use this as an action attribute for a form.
You need to POST the data to a server-side script and use that to send the data, such as PHP's mail() function, assuming you have the server set up to do so.
If I understand correctly, you wish to have everything in one page and execute it from the same page.
You can use the following code to send mail from a single page, for example index.php or contact.php
The only difference between this one and my original answer is the where the action has been left blank.
It is better to use header('Location: thank_you.php'); instead of echo in the PHP handler to redirect the user to another page afterwards.
Copy the entire code below into one file.
<?php
if(isset($_POST['submit'])){
$to = "xyz#gmai.com"; // this is your Email address
$from= $_POST['email']; // this is the sender's Email address
$name = $_POST['name'];
$subject = $_POST['contactnumber'];
$message = $name . " Contact Number:" . "\n\n" . $_POST['contactnumber'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
<tr>
<td width="336" height="148" colspan="9">
<input type="text" name="name" style="width:336; height:40; padding-left:10px" placeholder="Name" required>
<img src="images/spacer.gif" width="336" height="14" alt="">
<input type="email" name="email" style="width:336; height:40; padding-left:10px" placeholder="Email Id" required>
<img src="images/spacer.gif" width="336" height="14" alt="">
<input type="tel" name="contactnumber" style="width:336; height:40; padding-left:10px" placeholder="Contact Number" required>
</td>
</tr>
<tr>
<td width="186" height="65" colspan="7">
<input type="submit" value="Submit" style="width:186; height:65; background-color:black; color:white;"></td>
</tr>
</tr>
</form>
</body>
check more in this question

using a table name by php in a submit form

I want the user choose a table name in mysql database and then I can add a data by textbox of a form inside the field.
I used PHP $_POST[ ] to send table name to the adding form. but in the adding form; when I submit the add button; the table name has been lost.
I have searched a lot and tested session and constant to hold the table name value; but
didn't get the desired result.
Any help will be greatly appreciated.
here is the code of the page which selecting the table name:
<form action="change_products.php" method="post" name="select_table">
<select name="edit_products" >
<option <?php if($_POST['edit_products'] == "cabin") echo "selected='selected'"; ?> value="cabin">Cabin case</option>
<option <?php if($_POST['edit_products'] == "cabin_door") echo "selected='selected'"; ?> value="cabin_door">Cabin door</option>
</select>
<input type="submit" value="OK">
</form>
and this is the code of the adding form in "change_products.php" page.
<?
include('functions.php'); //the database info
define('selected_table', $_POST['edit_products']);
?>
<form method="post">
<table>
<tr>
<td>Mark:</td>
<td><input type="text" name="mark" /></td>
</tr>
<tr>
<td><input type="submit" name="add" value="New" /></td>
</tr>
</table>
<?
if (isset($_POST['add']))
{
$mark=$_POST['mark'];
mysql_query("INSERT INTO ".selected_table." (mark) VALUES ('$mark')");
}
?>
</form>
You didn't set $_POST['add'], thus, the last part of PHP code in change_products.php does not run.

Simple script issue?

for some reason I cannot get any form to work correctly on my website, I even went to w3school and copied a simple test form to see if it works, and it does not, here it is:
welcome.php:
<?
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
?>
form:
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
I'm not sure if it matters or not, but I tried with and without brackets, and still I get a blank page, in explorer I get a 500 Error, most likely causes is maintenance or Programming Error", but I had the same issue last night so I doubt its maintenance, and everything else works.
Remove the beginning <? and ending ?> from your welcome.php.
Your form uses get and you're reading from $_POST.
Either change html to
<form action="welcome.php" method="post">
or change the php to
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
Also, make sure the value is present using the isset
Welcome <?php echo isset($_GET["fname"]) ? $_GET["fname"] : "Guest"; ?>!<br />
When you use $_POST["fname"] you should also specify post as method in your form
welcome.php:
<?
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
?>
form:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>