311 Posts in 83 Topics by 149 members
| Go to End | Next > | |
| Author | Topic: | 5235 Views |
-
integrate external PHP code

28 December 2008 at 8:39am
Hello,
I am migrating my website to Silverstripe. But I have a question: On my old page I used a special registration form that generates productkeys. I want to integrate this form in my new page with silverstripe.How can I integrate the external PHP-code in the CMS??
-
Re: integrate external PHP code

28 December 2008 at 5:44pm
Of course you can do that. That's what's so great about Silverstripe -- you're never stuck with just the tools they give you.
I'd start with the recipe on custom forms here:
http://doc.silverstripe.com/doku.php?id=recipes:forms&s=recipes%20formsIf you can't get it working, post your code, and I'd be happy to help you out.
-
Re: integrate external PHP code

19 January 2009 at 5:00am
Is there any other possibility to integrate PHP code? For example a wrapper or something like this. I am looking for an opportunity, when I use the code does not adapt.
Thank you for helping!
-
Re: integrate external PHP code

19 January 2009 at 6:36am
There's no reason something like that shouldn't work if you follow the tutorial. If you want, post what you're working on and one of us can help you out.
-
Re: integrate external PHP code

22 March 2009 at 2:15pm
I tried to ask the similar question on another SilverStripe forum
http://www.silverstripe.org/form-questions/show/256267#post256267
While tutorial describes form with action to write into DB, I am more interested in reading from DB
Victor
-
Re: integrate external PHP code

23 March 2009 at 5:15am Last edited: 23 March 2009 5:16am
You don't need custom PHP to do this. Use the wonderful MVC framework that Silverstripe provides.
Here's your code:
// database info
$query ="SELECT * FROM StaffPage WHERE `lastname` LIKE '$_POST[last_name]%'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result)==0 ) {print("Not found "); return;
}while($row = mysql_fetch_array($result)) {
echo $row[lastname].", ".$row[lfirstname];
}
?>Now I want to put on some page form which is
<form action='./dosearch.php'>
<input type='text' name='last_name'>
<input type='submit'>
</form>Here's how to do it in Silverstripe:
function StaffSearchForm()
{
return new Form(
$this,
"StaffSearchForm",
new FieldSet(new TextField('StaffSearch','')),
new FieldSet(new FormAction('doStaffSearch','Search'))
);
}function doStaffSearch($data, $form)
{
$results = DataObject::get("StaffPage","lastname LIKE '%".$data['StaffSearch']."%'");
return $this->customise(array('Results' => $results))->renderWith(array('StaffSearch_results','Page'));
}
StaffPage.ss$StaffSearchForm
StaffSearch_results.ss
$StaffSearchForm
<% if Results %>
<ul>
<% control Results %>
<li><a href="$Link">$firstname $lastname</a></li>
<% end_control %>
</ul>
<% else %>
There were no results that matched your query.
<% end_if %>I would also look at the recipe on forms if I were you. Also, the LIKE operator is not the best way to do search in MySQL. It's case sensitive and far too exact to return reliable results. I would use the MATCH and AGAINST functions and order by relevance.
-
Re: integrate external PHP code

23 March 2009 at 10:29pm Last edited: 24 March 2009 1:01am
Thanks! But as no good deed goes unpunished I will need to ask few more questions:
We are trying to build a Department site and People are divided into Faculty, Staff, Students. Currently we are in very early stage and decided (but decision could be changed) to have separate FacultyPage, StaffPage, StudentPage with the same fields, because we want to have the neither the same "fill forms" nor outputs
Right now I am trying to search just Staff by lastname. But the general idea was to search all, so external (working) php script has UNION ALL in querry, also we matched against
(we want lastname starting from ... and firstname starting from ... (those may be empty); here lastname and firstname are fields name in DB`lastname` LIKE '$_POST[lastname]%' AND `firstname` LIKE '$_POST[firstname]%'
[quota]
I would also look at the recipe on forms if I were you. Also, the LIKE operator is not the best way to do search in MySQL. It's case sensitive and far too exact to return reliable results. I would use the MATCH and AGAINST functions and order by relevance.
[/quota]No, we really want to order by lastname and we are looking for 'lastname' starts from not contains the string. I am not sure that you are right about case sensitivity: always worked as not case sensitive. Further
http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html says
"The following two statements illustrate that string comparisons are not case sensitive unless one of the operands is a binary string:"
mysql> SELECT 'abc' LIKE 'ABC';
mysql> SELECT 'abc' LIKE BINARY 'ABC';Thanks in advance. Victor
-
Re: integrate external PHP code

24 March 2009 at 1:33am
I ran into little problem:
If search ends in no results it does not display "Your search ..." message but a complete blank
PS Search form is on StaffHolder while people are StaffPage (as in tutorial-2 but much more fields to fill)
Victor
| 5235 Views | ||
| Go to Top | Next > |


