Forum Replies Created
- AuthorPosts
waubain
ParticipantI got this to work to my satisfaction. Thank you.
I will also look at the example code you provided, as a possible alternative.
waubain
ParticipantI figured out a solution. I built a plain select input in the php file which was then returned to the QuForm element.
Since I am a beginner, improvements are welcome.
Thanks.php file
//array not shown if ( isset( $_GET['id'] ) && !empty( $_GET['id'] )){ $mdate = $_GET['id']; } echo '<select>'; echo '<option value="">Choose a speaker</option>'; $speakers = array(); foreach($info_decoded as $row) { if (($row['meetdate']) == $mdate) { $speakers[] = $row['speaker']; } } foreach($speakers as $item){ echo '<option value="' . $item . '">' . $item . '</option>'; }; echo '</select>';
form php
<!-- Begin Speaker Select element --> <div class="quform-element quform-element-select quform-huge"> <div class="quform-spacer"> <label for="speaker">Speaker<span class="quform-required">*</span></label> <div class="quform-input"> <select class="quform-tooltip" id="speaker" name="speaker" title="Speaker"> <option value="">Choose meeting date first!</option> </select> </div> </div> </div> <!-- End Speaker Select element -->
April 22, 2019 at 7:18 pm in reply to: Validator to check if file already exists before uploading #29135waubain
ParticipantWorks perfectly. Thank you for the code and a great product.
April 21, 2019 at 12:07 am in reply to: Validator to check if file already exists before uploading #29116waubain
ParticipantThe below piece of code works in a test page, but I don’t know where I can place it to make it work properly within your code, if at all.
The form is being used to upload a file to a directory and not to send an email or to a database.
/** Create an array of file names in handout directory to check if file already exists **/ $dir = '../../handouts'; // get directory files $dirfilenames = scandir($dir); //get name of file to be uploaded $files = $form->getValue('upload'); $filename = $files[0]['filename']; //check if file exists foreach( $dirfilenames as $value ){ if( $value == $filename ){ //terminating script with a message using exit() exit('File already exists!'); } } /** End of file exists check **/ // Save to a MySQL database
April 19, 2019 at 8:27 pm in reply to: Validator to check if file already exists before uploading #29111waubain
ParticipantI realized that ‘inArray’ will not work at this point since the ‘filename’ does not yet exist until farther in the code.
waubain
ParticipantThis may or may not apply to your situation. I also was getting a lot of spam. One common denominator of all the spam that I received is that it contained a URL link. Since my users would have no reason so submit a URL, I created a Validator that check the textarea for a URL and prevented the form from being submitted, and alerted the users of no URLs.
Since doing this, I have not gotten any spam submitted. I am not a programmer, but this code worked for me.
/** * Quform_Validator_URL * * Checks that the text block does not have a embedded URL * * @package Quform * @subpackage Validator * @copyright Copyright (c) 2009-2015 ThemeCatcher (http://www.themecatcher.net) */ class Quform_Validator_Url extends Quform_Validator_Abstract { /** * Error message templates * @var array */ protected $_messageTemplates = array( 'empty' => 'URLs not allowed' ); /** * Checks whether the given value is empty. * * @param $value The value to check * @return boolean True if valid false otherwise */ public function isValid($value) { $valid = true; if (stristr($value, 'http')||stristr($value, 'www.') !== false) { $this->addMessage($this->_messageTemplates['empty']); $valid = false; } return $valid; } }
waubain
ParticipantThat worked thank you.
waubain
ParticipantI am still having a problem. The filename value in the new array of form inputs are showing a NULL for the filename. I am using the single file upload.
“filename”:null
All of the other form elements are populating the new array as expected. Does the array need to be decoded or parsed?
this is my code
/** Custom code section #1 - see documentation for examples **/ //Capture form input values $ho_meetdate = $form->getValue('meetingdate'); $ho_acronym = $form->getValue('ho_acronym'); $ho_type = $form->getValue('ho_type'); //get uploaded file name $files = $form->getValue('upload'); $ofilename = ($files[0]['filename']); //Rename uploaded file $newfilename = $ho_acronym . $ho_type; //Create new array if does not exist or append if exists $arr_file = array(); $arr_file['meetdate'] = $ho_meetdate; $arr_file['acronym'] = $ho_acronym; $arr_file['type'] = $ho_type; $arr_file['ofilename']= $ofilename; $arr_file['nfilename']= $newfilename; //Save the JSON string to a text file. $ho_encoded = json_encode($arr_file); file_put_contents("../../editor/handout_arrayTest.txt", $ho_encoded); /** End custom code section #1 **/
Array contents = {“meetdate”:”2019-05-02″,”acronym”:”aa”,”type”:”_ho_1c.pdf”,”ofilename”:null,”nfilename”:”aa_ho_1c.pdf”}
Thank you for your help
April 3, 2019 at 1:02 pm in reply to: changing file name of single upload file before saving to server folder #28943waubain
ParticipantI got this working. The file name retained the .pdf without adding it back, so I was getting an additional period at the end.
- AuthorPosts