Forums

[Solved] Using PHP with the forms -- View solution

Winchester 06 Jul, 2011
Hi,

I am using Chrono Forms and ChronoConnectivity to display and manage a song listing.

This listing is in a database table and will be managed by manger levels and up. Most of the managers don't know how to use Joomla. They just want a way to edit view and edit the list.

The list includes an mp3 file player (dewplayer plugin). The problem is that the Dewplayer plugin syntax doesn't work in the table which is currently be displayed using EasyTable extension. So as a work around I insert the entire object tag with all the params into the field where I want the mp3 to play in.

Since the managers could easily make mistakes when adding new song/mp3s, I figure CF/CC would be the best solution.

I've already set up the CF form and the CC table view. Now I need to set it so that the manager can upload the new mp3 to a specific folder for all the mp3 files and for the form to append the file name to the object tag and save that to the DB table.

eg: If they upload an MP3 named new_song.mp3 it will got to http://www.mysite.com/songs/mp3s/.

Next the form takes the name of the MP3 file (new_song.mp3) and add it to the object tag codes

<object width="200" height="20" bgcolor="#FFFFFF" data="http://www.mysite.com/plugins/content/dewplayer.swf?son=http://www.mysite.com/songs/mp3s/new_song.mp3&autoplay=0&autoreplay=0&showtime=1" type="application/x-shockwave-flash">
<param value="opaque" name="wmode">
<param value="http://www.mysite.com/plugins/content/dewplayer.swf?son=http://www.mysite.com/songs/mp3s/new_song.mp3&autoplay=0&autoreplay=0&showtime=1" name="movie">
</object>


Notice it places the URL for the mp3 file in 2 places. The entire object tag codes is to me saved to the DB so the view table will have the full code to show the player and play the file.

I figure that I will need to use PHP to do this. But I would like to know how to and also how to get the mp3 file to upload to that special folder.

Does anyone have any idea how to go about this?

Anything will be well appreciated.

Best regards,
Winchester
Winchester 06 Jul, 2011
Ok.. I've figured out the Upload directory part. So I just need to know how to append the file name to the <object></object> tags.
GreyHead 07 Jul, 2011
Hi Winchester ,

You can use the OnSubmit Before Email box to build the string to save to the Database
<?php
$song_name = JRequest::gestString('input_name', '', 'post');
if ( $song_name ) {
  $object = '<object width="200" height="20" bgcolor="#FFFFFF" data="http://www.mysite.com/plugins/content/dewplayer.swf?son=http://www.mysite.com/songs/mp3s/'.$song_name.'&autoplay=0&autoreplay=0&showtime=1" type="application/x-shockwave-flash">
<param value="opaque" name="wmode">
<param value="http://www.mysite.com/plugins/content/dewplayer.swf?son=http://www.mysite.com/songs/mp3s/'.$song_name.'&autoplay=0&autoreplay=0&showtime=1" name="movie">
</object>';
  JRequest::setVar('record_name', $object);
}
?>


Bob

Personally I'd build this when it is needed and only save the song path/name in the database record.
Winchester 07 Jul, 2011
Hi GreyHead,

Thank you very much.

I agree with leaving just the path/name only in the db. The thing is that it was supposed to be a set-it and leave-it table. But later they decided that they wanted to be able to make changes to it.

Also, I'm one of those persons that can figure out what needs to be done to get things like this done. Very good with planning and troubleshooting. I can tell if the codes (php/js) are what I need to get the job done or not by looking at it. But, I just don't know how to write them myself. I am learning slowly but surely though.

I will give this a try. May be later I will take out the object tag codes out of the table. For now, they just need to be able to edit the list. Thanks again for the help.

Best regards,
Winchester
Winchester 07 Jul, 2011


$song_name = JRequest::gestString('input_name', '', 'post');



Should this be getString?


if ( $song name ) {



Is the underscore missing from this variable? Is it supposed to be $song_name?

Also, it seems to be missing a closing bracket for the IF condition. I'm not sure if it should go before the JRequest::setVar('field_name','$object'); or after it.

Thanks again GreyHead..🙂
Winchester 08 Jul, 2011
I finally got what I wanted to do to work. I didn't use PHP though. Instead I wrote a simple javascript.

Incase anyone needs to to do something like this, here are the codes. I use this to copy the name of the mp3 file from the mp3_file_name input field, append the JosDewPlayer plugin syntax around it and then place everything into the player input field.

The listing is displayed using ChronoConnectivity. Just remember that if your going to use plugins from another extension (like JosDewPlayer plugin) you have to enable Mambot for the table.

Form Codes:

...
<div class="form_item">
	<div class="form_element cf_textbox">
		<label class="cf_label" style="width: 150px;">MP3 File Name</label>
		<input onChange="loadPlayer();" class="cf_inputbox" maxlength="150" size="30" title="" id="mp3_file_name" name="mp3_file_name" type="text" />
	</div>
	<div class="cfclear"> </div>
</div>

<div class="form_item">
	<div class="form_element cf_textarea">
		<label class="cf_label" style="width: 150px;">MP3 Player Codes</label>
		<textarea readonly="readonly" class="cf_inputbox" rows="4" id="player" title="" cols="30" name="player"></textarea>
		<a class="tooltiplink" onclick="return false;"><img height="16" border="0" width="16" class="tooltipimg" alt="" src="components/com_chronocontact/css/images/tooltip.png"/></a>
		<input class="clear-but" type="button" value="Clear" title="Clear MP3 Player Codes" onclick="document.ChronoContact_ird_top_250.Track.value=''">
		<div class="tooltipdiv">MP3 Player Codes :: No need to change anything here. You just need to change the name is the MP3 File Name field and this will change automatically.</div>
	</div>
	<div class="cfclear"> </div>
</div>
...


JavaScript: This you place into the javascript block below your Form code block in CF.

	function loadPlayer(){
		document.ChronoContact_mp3_form.player.value = '{play}images/stories/mp3/' + document.ChronoContact_mp3_form.mp3_file_name.value + '{/play}';
	}


Note:

In the javascript, you have to create an object for each of the form elements that are involved in the what you want the script to do. The method I use create the objects is as follows "Object_Type.Form_Name.Field_Name.Field_Attribute". It's sort of like how you would select in CSS with (dots) inbetween instead of spaces.

- Object_Type: document
- Form name: ChronoContact_mp3_form (This is generated by CF)
- Field name: player (the name of the form I want to take the text from. the name of the field that I want to final data/text to be placed into is named mp3_file_name.)
- Field_Attribute: value (the value attribute of the field refers to the data/text inside of the field.)

So for my objects I have:
document.ChronoContact_mp3_form.player.value and document.ChronoContact_mp3_form.mp3_file_name.value

So the next thing to do is to create a function to call to do the job. In my script the my function is named loadPlayer(){RULES & CONDITIONS GOES BETWEEN HERE} and inbetween I place the rules of my function.

In my case, my function rule was simple. It's basically, object2 = '{play}path/to/mp3/folder/' + object1 + '{/play}'

Note that object1 is document.ChronoContact_mp3_form.mp3_file_name.value and object2 is document.ChronoContact_mp3_form.player.value.

The {play}{/play} tags belongs to the JosDewPlayer plugin. The path/to/mp3/folder/ portion is needed so that JosDewPlayer can know where I store my MP3 files. I used the + to join them together, but you should note that the text that I added are contained between single quotes. At the end of my rule, there's a semi-colon which tells the script that it's the end of that rule. I can add another rule if I need to which will also end with a semi-colon.

Lastly we add the event to call up my function on the field that will be typed into. For this I used onChange() and to make the call I added the onChange="loadPlayer();" attribute to the input field tag.

<input onChange="loadPlayer();" class="cf_inputbox" maxlength="150" size="30" title="" id="mp3_file_name" name="mp3_file_name" type="text" />


Oh yea, I almost forgot about the button to clear the field. If you look at the codes in my form you will notice that I make the player field readonly. But, from time to time I think the user may need to remove the player for a given row on the MP3 song list. This will give them a chance to remove all the text from the field. It's a very simple input button using a onClick() attribute with a rule.


<input class="clear-but" type="button" value="Clear" title="Clear MP3 Player Codes" onclick="document.ChronoContact_mp3_form.player.value=''">


Note: onclick="document.ChronoContact_mp3_form.player.value=''".

This is basically telling the button to replace the content of the field (value) with nothing. Like in the javascript, it used a object to tell the button with field it should apply to. The equal operator tells the button what the objects should become and on the other side of the equal operator nothing is represented with a pair of single quotes with nothing between them.

I used Solmetra Flash Uploader v1.02 to upload the mp3 files which is done separately from the form. I tired adding the uploader to the form using an iframe, but it was breaking the page. So I used a wrapper module to place it beside the form. I have to use NoNumber's Advanced Module Manager to force it to load with the for in Joomla 1.5. I'm not sure if the problem would be the same in 1.6. Also, I think there are better solutions for uploading files, but it's hard to find useful codes in the forums (since most don't really explains their codes or even show what the whole codes look like).

Anyways, I hope there's someone out there that this can help.

Best Regards,
Winchester
GreyHead 08 Jul, 2011
Hi Winchester,

Nice solution :-)

Apologies for my typos :-(

Bob
Winchester 08 Jul, 2011
Hey GreyHead,

Hi Winchester,
Nice solution :-)



Thanks🙂 It's the least I can do to tell everyone how I resolved this.

Hi Winchester,
Apologies for my typos :-(



It's ok... I truly appreciated the help even though I didn't use it after all. I change it because when I thought about it, it would've been nicer if it could be done on-the-fly instead. So I though a JS solution would work better.

There are still a few other things that I need to do with the list. I need to install a Confirm Delete alert and also to have the numbers from 1 to 250 for the song position on the list.

I have already found a solution for the confirm delete which I'm about to implement, but can't seem to find anything on the numbering. I will post my solution for that also if I manage to find one.

There are 2 issues that I wanted to ask about. I'm getting an "You are not authorized..." message whenever I try to submit an entry using my main account which is also a Super Administrator account. It works fine using the admin account. I double checked the permissions hundreds of times and they are all correct. At first I though it was a SEF issue. The form is submitted to itself, but when the SEF changes the link it throws the error. This is thorn down by the fact that it works fine using the Admin account.

The second issue seems to be somewhat related to the first issue. Like the first issue, it affects ALL the user accounts EXCEPT for the Admin account. The issue is that whenever I click on the New Record link, the form comes up with the fields already populated. It seem that it populate it with the information from the row with the similar id as my Joomla user id. eg: If my Joomla user id is 54 it will populate the fields with information from the song row with id 54 (Mp3 list's DB table is 54). Again, this issue occurs will all other accounts except for the Admin account. with the admin account it comes up blank like it should.

I don't know enough about CF & CC core codes to be able to troubleshoot it effectively. I'm thinking may be you would know enough to be able to better than me.

Best regards,
Winchester
GreyHead 09 Jul, 2011
Hi Winchester,

I've only seen the 'not authorised' message when the settings are wrong or I'm not logged into the front-end with the correct user. In practice I usually code my own permissions into the listing to avoid problems like this :-(

There is a thread here about the double posting problem. Again, I don't use the new or edit record links but link directly to the form and use the Profile plug-in to load the data if needed.

Bob
Winchester 09 Jul, 2011
Yes.. I'm using the profile page to setup a detail view for the table rows. I'm thinking I could use this for the confirm delete solution.

Fortunately, it only about 4 people that will have access to the add/edit/delete buttons. I'll look more into a proper solution later.

I think I have everything else worked out. What I have to work out now is to get the JosDewPlayer plugin to working in the form I created for the Detail View page...

I have Mambot set to Yes for the form, but it's not working. Any ideas on how to get it working?

Winchester
GreyHead 12 Jul, 2011
Hi Winchester,

I don't' know anything about the JosDewPlayer plug-in :-( In my Limited experience plug-ins/mambots 'just work'.

It's possible that the player is looking for a trigger event that ChronoForms doesn't set - you'd need to dig into both sets of code to check just what is needed.

Bob
This topic is locked and no more replies can be posted.