I'm using PHP and smarty for my website. I'm getting a URL in address bar and I want to use the values from URL into smaarty template. So is it possible to do that? If yes can you explain? For your understanding I'm giving you the URL as follows:
http://localhost/eprime/entprm/web/control/modules/enquiries/manage_contact_us.php?contact_id=56&contact_full_name=ZainabJuzerBhavnagarwala&contact_email_id=fatemabhav21#gmail.com&op=view&reply_to_enquiry_suc=1&from_date=11/09/2000&to_date=11/09/2013
Suppose from the above URL I want to access the values of variables contact_full_name and contact_email_id in my smarty template which is currently being displaed. Can you explain me how could I achieve this?
Actually I tried the following code but it didn't output anything.
<input type="text" name="contact_full_name" id="contact_full_name" value="{ if $data.contact_full_name!=''} {$data.contact_full_name|capitalize} {else} {$contact_full_name|capitalize} {/if}" class="">
Thanks in advance.
Look at smarty reserved variables :
{$smarty.get.contact_email_id}
Look at smarty reserved variables :
{$smarty.get.contact_email_id}
Since Smarty will output the contents of the variable, if present and nothing if it isn't, then you should just:-
<input type="text" name="contact_full_name" id="contact_full_name" value="{$smarty.get.contact_full_name|capitalize}" class="" />
(anyone can copy and paste LOL)
and per previous answer:
adding $smarty->debugging_ctrl='URL'; to your php script and &SMARTY_DEBUG to the URL will popup your assigned variables (but not get and post)
Related
I am trying to input submit value and want to pass the value to another page through GET but for that I have to use two Clicks button.
I want the same in a single click. Help required.
Code:-
<form method="post">
<input name="inwardid" type="text" id="inwardid" />
<?php $inwardid = $_POST['inwardid']; ?>
<input type="submit" value="Next" />
</form>
<a href="addbook.php?up=<?php echo $inwardid; ?>"><button>Proceed</button>
You want to send the value the user typed in to the other page. So use this for your <form>:
<form method="POST" action="addbook.php">
<input name="up" type="text" id="up">
<input type="submit" value="Proceed">
</form>
To access the value in addbook.php, use $_POST['up'].
This will send the value the user typed in the input label (type="text") to the addbook.php page, using a $_POST. No need for a $_GET, $_POST will do just fine.
As you deliberately asked for method GET, my solution shows you GET!
You must know there is no security issue when using GET. It depends what you want to do. GET is useful if you want to use a dynamic code in multiple ways depending on some some variables that you do not want to hard-code in your script, or simply do not want to send files or other huge data.
Lets admit a newspaper has a site called breaking_news.php and you want to access the breaking news of November 8, 2016you could use this as :
breaking_news.php?y=2018&m=11&d=08
The fact that one can see your GET vars means nothing. Even by using POST one can see your variables by looking at your code. And one way or the other you must protect against code injection and brute force.
But if your not in the mood to show this vars to your visitor you can use URL rewriting to rewrite the url above in the browser as
RewriteRule ^breaking/(.*)/(.*)/(.*)/news\.html$ breaking_news.php?y=$1&m=$2&d=$3 [NC,L]
so you send your visitor to see the (rewritten)URL
breaking/2018/11/08/news.html
but what the web-server is showing him is:
breaking_news.php?y=2018&m=11&d=08
A reason to use this if for example when you want your dynamic site to be taken into consideration by some searching engine as a static site, and get indexed. But this is again another battle field.
Second, you want to send the variable to "addbook.php", and not to itself.
Your question sounded like you want to send to "another page" not to the same page.
Third, I can see in your code snippet you want to submit the variable "up" and not "inwardid", as you did in your code.
And also I can see you want the "submit" button to be called "Proceed".
Your code would look like this:
<form method="GET" enctype="application/x-www-form-urlencoded" action="addbook.php" target="_blank">
<input name="up" type="text" id="inwardid" />
<input type="submit" value="Proceed" />
</form>
As I said you must protect against injection, and this means for example, that in the "addbook.php",to whom you are sending the variables you must write some code that protects you against this issues. As your question is not in this direction I will not enter this subject.
To avoid problems with special chars you must "url-encode" your variable specially when sending them per POST method. In this case you must use this enctype if your handling text. Because this enc-type is transforming special chars into the corresponding ASCII HEX-Values.
Using GET your safe, because GET cant send in another enc-type. So your variable will automatically be url-encoded and you receive a string that is compliant to RFC 3986 similar by using:
rawurlencode($str)
Lets admit someone smart guy fills in a your input box the following code, in the desire to break your site. (This here is not exactly a dangerous code but it looks like those who are.)
<?php echo "\"?> sample code in c# and c++"; ?>
using enctype="application/x-www-form-urlencoded" this will become something like this:
%3C%3Fphp%20echo%20%22%5C%22%3F%3E%20sample%20code%20in%20c%23%20and%20c%2B%2B%22%3B%20%3F%3E
what makes it safe to be transported in a URL, and after receiving and cleaning it using
strip_tags(rawurldecode($_GET['str']))
it would output something like this, what is a harmless string.
sample code in c# and c++
Here I am again... I've been watching some tutorials and I'm now in good way on php programing...
What I want to know is: with a template manager like for example smarty, you can make 1 php page with the code and redirect it to the view html file... something like this on the php...
$a = new Trabalhos();
$id = new Users();
$sm->assign("id", $a->select());
if (isset($_GET['del'])) {
$a->setId($_GET['del']);
$a->delete();
}
if (isset($_POST['id'])
and isset ($_POST['trolha'])
and isset($_POST['padeiro'])
and isset($_POST['arquitecto'])
and isset($_POST['engenheiro'])
and isset($_POST['medico'])
and ! isset($_GET['edit'])) {
$a->setId($_POST['id']);
$a->setTrolha($_POST['trolha']);
$a->setPadeiro($_POST['padeiro']);
$a->setArquitecto($_POST['arquitecto']);
$a->setEngenheiro($_POST['engenheiro']);
$a->setMedico($_POST['medico']);
$a->insert();
}
$lista = $a->select();
$sm->assign("lista", $lista);
$sm->display("trabalhos.html");
Then I make the view page in trabalhos.html and I put this:
<form method="post">
| id <select name ="id">
{foreach from=$id item=d}
<option value ="{$d.id}">{$d.id}</option>
{/foreach}
</select>
| Trolha <input name ="trolha" type="text" />
| Padeiro <input name ="padeiro" type="text" />
| Arquitecto <input name ="arquitecto" type="text" />
| Engenheiro <input name ="engenheiro" type="text" />
| Medico <input name ="medico" type="text" />
<input type="submit" value="Guardar"/>
</form><br>
<table border="1">
<tr>
<td>ID</td>
<td>Trolha</td>
<td>Padeiro</td>
<td>Arquitecto</td>
<td>Engenheiro</td>
<td>Medico</td>
<td>Acoes</td>
</tr>
{foreach from = $lista item = row}
<tr>
<td>{$row.id}</td>
<td>{$row.trolha}</td>
<td>{$row.padeiro}</td>
<td>{$row.arquitecto}</td>
<td>{$row.engenheiro}</td>
<td>{$row.medico}</td>
<td>Edit | <a href="?del={$row.id}">Delete</td>
</tr>
{/foreach}
</table>
OK till there I get it and I make it work with the help of the tutorial and giving my variables
Now what I really want to know is how can I do the same without the help of external template managers, everyone will say that is easier with this and that, but I'm looking to learn php, not to run pre-made scripts, if you know what I mean
Right now I don't trust on external code... to trust it I need to understand it
So if they made it work with smarty I have to make it work by myself right?
Is there need of other languages out of php to do it? like java or something similar?
Or can I do it just with php and html coding?
If is possible to do it just with php and html coding can anyone tell me for example how will I make that column with the foreach php function work? And how do I transmit to the html the variables info?
Really sorry for that huge post, but I didn't see anything like what I'm asking in here and on google i just see people and forums talking about template managers, and that's not what I'm looking for ;)
Thank you very much for the answers last post got a positive one ;)
Trying to write your own template engine is a hard task. But you can do it in plain PHP, not need for other language.
Basically, your template engine will need 2 things in order to work:
Templates. Your trabalhos.html file is a template. It's a HTML file that contains special placeholders (like {$d.id}) that have a particular meaning for your template engine.
Variables. If you want to do something useful with your templates, you must provides variables to work with (this is what you do with an instruction like this $a->setId($_POST['id']);).
Now what you need to do is write some code that is able to parse your template files (recognize the placeholders you defined) and work with them. This is quite easy to do if you only need to replace placeholders with the value of a variable but will get tricky as soon as you start to implement features a little more complex like loops.
In addition to that, you also need to write some code that enables you to bind values to your variables as well as objects to store these.
This is a huge job but if your aim is to learn PHP, it's a really good way. Good luck!
You can use file write function.
$file = fopen("trabalhos.html","w");
fwrite($file,$lista);
fclose($file);
I need to change the login page of WHMCS since the current one is a bit confusing with all those additional options which better be shown ofter user is logged in. I want to change the clientarea.php to just show a small dialogbox (would look cool after I add css and some jquery) on the whole page which asks the user to login.
I tried to find the tpl file specifically for clientarea but could not find one. The clientarea.php file is encoded so can't really edit that.
Any guesses?
Your best bet is editing login.tpl
and then simply having inside your dialogue box
<form action="{$systemsslurl}dologin.php?goto=clientarea.php" method="post" name="frmlogin">
<label>Email address</label>
<input type="email" name="username" placeholder="Your Email">
<label>Password</label>
<input type="password" name="password">
<button type="submit">Login</button>
</form>
<a href="/pwreset.php" >Forgotten your Password? Click Here</a>
The above form can be placed in any tpl file and will work as expected
Note: the ?goto clause can be used to redirect the logged in user we use this to
navigate the user back to /cart.php?a=checkout when they are ready to buy.
You may use jQuery.append() and custom tags in .TPL files.
The client area is split up into several different template files. The files I think you should look at are header.tpl, login.tpl and footer.tpl. You should also look at the WHMCS documentation at http://docs.whmcs.com/Client_Area_Template_Files and http://docs.whmcs.com/Developer_Resources#Display_Customisation. WHMCS also offers support for these kinds of things as well.
I think the easiest way is to use the variables already set in Smarty.
The $loginpage variable returns true if login page is shown.
In header.tpl use the following code around the content you do not wish to show on the login page:
{if $loginpage ne "true"}
//nav menu etc
{/if}
You can also use this on your footer in the same way. Then it's simply a case of modifying login.tpl to meet you needs.
If you want to show a different header and footer on the login page you could add an else statement like so:
{if $loginpage ne "true"}
//nav menu etc
{else}
//Different Content
{/if}
Sources: {debug} - This dumps all Smarty variables to a window.
You can Simply create your own new custom page(php +Template File ) for your Login and You can validate the User Login using WHMCS API functions.
How to Create Custom Page : http://forum.whmcs.com/showthread.php?20267-Creating-Custom-Pages
Login Validate API : http://docs.whmcs.com/API:Validate_Login
Very easy.
As I have created ajax login to WHMCS Clientarea.
Create a file in root with name ajaxlogin.php and check email with encripted password,
after that set session uid and upw (Password hash).
thats all.
1st you must know what Client Version you are using.
To do this on vs 5.3.6 Go to Tab Setup click on General Settings and See Template.
This in source is located at /whmcs/templates
You can copy a directory and create your own template directory and it will show up in the General Settings.
Once you have done that, you will probably have to modify sever pages to get the desired effect.
I have a have in PHP and I have common fields such as 'Name' and 'Surname'.
Now when the user visits the page e.g. http://www.example.com/form.php the form fields 'Name' and 'Surname' are empty.
I would like to now have a link similar to this http://www.example.com/form.php?name=John
so that when the client hits the link the PHP form will now have the name field already filled with 'John' in it.
I know this can be done in HTML but how can I do it in PHP?
Just to let to know I do not own the PHP form - I just want a link from my website to fill the PHP form (which I do not have control over).
Thanks in advance.
Can be done using $_GET
An associative array of variables passed to the current script via the URL parameters.
e.g.:
<? php
if(isset($_GET['name']))
{
$test = $_GET['name'];
}
?>
<html>
<body>
<form>
<input type="text" name="test" value="<?php if(isset($test)){echo "$test";}?>"/>
</form>
</body>
</html>
Note: code isnt tested or anything.. Also, there are possible security risks with getting values from your URL (can be considered user input), so make sure you are aware of that and how to prevent
You could store that value and then when you're about to output the input fields
you just pass along the stored value.
$name = $_GET['name'];
// ... later on
echo '<input type="text" value="'.$name.'"/>';
By using $_GET superglobal
<input name="name" value="<?php echo !empty($_GET['name']) ? $_GET['name'] : '';?>" />
<input name="surname" value="<?php echo !empty($_GET['surname']) ? $_GET['surname'] : '';?>" />
You can use the get method in php to get the name and make use of it
You can retrive this information by the $_GET["name"] function, or $_REQUEST["name"].
Reserver variables
Be carefull with those operations, you might have validation a/o security problem.
Note: if you are not sure that the "name" variable is set or not, you have to use also the
isset function to test it.
You can use the $_GET superglobal, so your input could look like this:
<input type="text" name="name" value="<?php if(isset($_GET['name'])) { echo $_GET['name']; } ?>" />
The $_REQUEST superglobal does a similar thing but I would just use $_GET.
It looks like everyone's answers here assume you are building the form yourself, which doesn't appear to be the case based on your question.
The thing that you want to do may or may not be possible. If the form accepts certain kinds of parameters in certain ways, you may be able to hook in to that functionality and set it up so that when someone clicks a link on your page, that information gets passed to the other page.
One way forms can accept this information is in the form of a "get" request. With this method, values are passed as part of the url, as in your example: http://www.example.com/form.php?name=John. Assuming your page has access to a php variable called $name, you can create a link from your code to build this kind of url like this:
Sign up!
If the page does not accept get parameters in this way (and I have a hard time imagining that they would), you may have to try other techniques to send along the information (assuming that they will even accept it!). The two other ways I imagine you could do this are by passing the value with "post" or creating a cookie for the page. If you tell us what page you are trying to set up this behavior on, we might be able to examine it and give you a better answer.
Ok this has had me banging my head for a while, I have posted on other forums but the info is sketchy at best, I hope you guys can help.
Scenerio:
I have a html landing page with a search field. here is the form:
<form method="get" action="URL TO EXTERNAL SEARCH" target=content>
<fieldset>
<input type="text" class="text" name="keywords" value="Search" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"maxlength="30" />
<input type="image" src="images/topnav/btn_search.png" class="button" />
</fieldset>
</form>
So it obviously takes the queried string and off it goes to an EXTERNAL domain which processors the string and returns the result as an HTML page, which in turn displays it in an Iframe named "content" within the same page.
<iframe src="DEFAULT CONTENT" name="content" width="803" height="1200" align="left">
Works a treat, however
PROBLEM:
I have other pages that DO NOT contain the Iframe but contain the search field.
WHAT I NEED TO ACHIEVE:
I need to enter the search string in a html page that DOES NOT contain an Iframe, and display in an Iframe on another html page.
I thought of using javascript/ jquery but due to cross site security issues it doesnt work hence PHP.
I know it can be done but lack the know how.
Any help suggestions would be greatly appreciated.
Thankyou
************UPDATE********************
Cheers for the suggestions so far but I have a few queries:
Thanks for the answer but I have a couple of questions so excuse my ignorance.
"landingpage.html" contains a search box but no Iframe to display the search result. "displaypage.html" contains a search box and an Iframe to display search results.
"displaypage.html" works fine; it sends the query string to the EXTERNAL server which returns a HTML page that I send to Iframe in "displaypage.html".
"landingpage.html" needs to direct the search query to "mysearchhandler.php" which in turn processors the query and returns the resulting html page to the Iframe located in "displaypage.html"
This is what I require to happen, I must have the search option on all my pages without an Iframe and be able to direct them to "displaypage.html"
My problem is lack of PHP understanding, so I am very grateful for your help guys but If possible could you place the code in context to relevant pages, it is easier for me to understand where the code goes and what it is doing.
Iam getting the stage where I am considering paying for the code, but I would like to
Anybody ?
What you could do is have a utility page that handles the search via PHP and returns the expected page.
<form method="get" action="mysearchhandler.php" target=content>
<input type="hidden" name="currentPage" value="thispage.php" />
And in mysearchhandler.php you could user http_get http://www.php.net/manual/en/function.http-get.php to pull down the information from the external search page. Use it with http_parse_message http://www.php.net/manual/en/function.http-parse-message.php
Use the hidden field to tell you which page to return, and update the page to look for the search data.
A simple mysearchhandler.php:
$search = clean($_POST['keywords']);
$currentPage = clean($_POST['currenPage']);
$url = <external search url with get parameters>
$searchResults = http_parse_message(http_get($url))->body;
//Need to validate $currentPage to prevent faked user input
include($currentPage); //Depending on your file system you may need to adjust this
Then in your page you could add:
if(exists($searchResults))
{
<Code to display the results>
}