Help with adding User allowed purchase pricing

I’m trying to modify this web video script, where currently it allows Admin to set/change the price of purchasing a video. I have copied the html form field code section from Admin, to the Users > manage-videos > edit section, to begin the modification of allowing the Video/Owner/User to set/change the price of purchasing the video.

So, currently, now in the User > manage-videos > edit Form, the new field now reflects the same video price as shown in the Admin field:

					<div class="form-group">
					<label class="col-md-12" for="cost">{{LANG video_price}}</label>
					<div class="col-md-12">
					<input id="cost" input type="text" name="video_price" class="form-control input-md" value="{{CONFIG video_price}}">
					</div>
					</div>
				</div>

(But, of course at this point the User can change the number in the field, but it isn’t being saved upon Form submit). What would be the next step? Adding a new column in the paid_videos db table, to echo what gets entered into ‘video_price’ column (from the Admin field), for example, named ‘up_user_vid_price’, and change the User > manage-videos > edit > Form field to:

					<div class="form-group">
					<label class="col-md-12" for="cost">{{LANG up_user_vid_price}}</label>
					<div class="col-md-12">
					<input id="cost" input type="text" name="up_user_vid_price" class="form-control input-md" value="{{CONFIG up_user_vid_price}}">
					</div>
					</div>
				</div>

I look forward to any guidance.

Guidance for what? Make a form, send data to a script, connect with your DB and run an update query.

Does the second input keyword throw any HTML syntax errors, or does it ignore such things?

<input id="cost" input type="text" name="video_price" class="form-control input-md" value="{{CONFIG video_price}}">

Thanks for your replies. Sorry, I’ve framed the question poorly. Let me try again.

I have this Form field:

<div class="form-group">
<label class="col-md-12" for="cost">Video Price</label>
<div class="col-md-12">
<input id="cost" input type="text" name="video_price" class="form-control input-md" value="{{CONFIG video_price}}">
</div>
</div>

I’d like the site User to be able to manually change the number that is showing ( {{CONFIG video_price}} in the input field, so that it can be saved.

Maybe this php needs modification?

<?php
if (IS_LOGGED == false) {
    $data = array('status' => 400, 'error' => 'Not logged in');
    echo json_encode($data);
    exit();
}


if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id'])) {
    $error = $lang->please_check_details;
}

if (empty($error)) {
    $id = PT_Secure($_POST['video-id']);
    $video = $db->where('id', $id)->getOne(T_VIDEOS);
    $can_update = false;
    if (PT_IsAdmin() == false) {
    	if ($db->where('user_id', $user->id)->where('id', $id)->getValue(T_VIDEOS, 'count(*)') > 0) {
    		$can_update = true;
    	}
    } else {
    	$can_update = true;
    }
    if ($can_update == true && !empty($video)) {
    	$video = PT_GetVideoByID($video, 0, 0, 0);
    	$thumbnail = $video->org_thumbnail;
    	if (!empty($_FILES['thumbnail']['tmp_name'])) {
	        $file_info   = array(
	            'file' => $_FILES['thumbnail']['tmp_name'],
	            'size' => $_FILES['thumbnail']['size'],
	            'name' => $_FILES['thumbnail']['name'],
	            'type' => $_FILES['thumbnail']['type'],
	            'allowed' => 'jpg,png,jpeg,gif',
	            'crop' => array(
	                'width' => 1076,
	                'height' => 604
	            )
	        );
	        $file_upload = PT_ShareFile($file_info);
	        if (!empty($file_upload['filename'])) {
	            $thumbnail = PT_Secure($file_upload['filename']);
	        }
	    }
	    $category_id = 0;
	    if (!empty($_POST['category_id'])) {
	        if (in_array($_POST['category_id'], array_keys($categories))) {
	            $category_id = PT_Secure($_POST['category_id']);
	        }
	    }
	    $link_regex = '/(http\:\/\/|https\:\/\/|www\.)([^\ ]+)/i';
	    $i          = 0;
	    preg_match_all($link_regex, PT_Secure($_POST['description']), $matches);
	    foreach ($matches[0] as $match) {
	        $match_url           = strip_tags($match);
	        $syntax              = '[a]' . urlencode($match_url) . '[/a]';
	        $_POST['description'] = str_replace($match, $syntax, $_POST['description']);
	    }
	    $featured = $video->featured;
	    if (isset($_POST['featured']) && PT_IsAdmin()) {
	    	$featured = PT_Secure($_POST['featured']);
	    }
	    $video_privacy = 0;
	    if (!empty($_POST['privacy'])) {
	        if (in_array($_POST['privacy'], array(0, 1, 2))) {
	            $video_privacy = PT_Secure($_POST['privacy']);
	        }
	    }
	    $age_restriction = 1;
        if (!empty($_POST['age_restriction'])) {
            if (in_array($_POST['age_restriction'], array(1, 2))) {
                $age_restriction = PT_Secure($_POST['age_restriction']);
            }
        }
	    $data_update = array(
	        'title' => PT_Secure($_POST['title']),
	        'description' => PT_Secure($_POST['description']),
	        'tags' => PT_Secure($_POST['tags']),
	        'category_id' => $category_id,
	        'featured' => $featured,
	        'thumbnail' => $thumbnail,
	        'privacy' => $video_privacy,
	        'age_restriction' => $age_restriction
	    );
	    $update  = $db->where('id', $id)->update(T_VIDEOS, $data_update);
	    if ($update) {
	        $data = array(
	            'status' => 200,
	            'message' => $success_icon . $lang->video_saved
	        );
	    }
    }
} else {
    $data = array(
        'status' => 400,
        'message' => $error_icon . $error
    );
}
?>

That looks correct. Duplicate the code you have for one of the other text fields, but refer to that new form field, do the appropriate validation, and copy it to the appropriate column in your $data_update array, by the look of it.

Thank you for your reply. Can you provide an example of what you’re suggesting?

You already have examples of the code in your post, you just need to change the names to reflect the new form field and the appropriate column.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.