Iframe With Variable Url In Php Variable
I have an html form and a php form. There is a dropdown menu with different URLs. When the submit button is pressed it returns an iFrame with the URL that was from the dropdown. My
Solution 1:
Well first of, the syntax errors:
$return['msg'] = \'<li><iframesrc=\" {$URL;}\" style="width:250px;height:250px;overflow:scroll;"id="MyFrame"></iframe></li>';
^ ^
I think in google you cant just straight up use src="google.com"
because Google is sending an "X-Frame-Options: SAMEORIGIN" response header you cannot simply set the src to "http://www.google.com" in a iframe.
Alternatively, you could use:
http://www.google.com/custom?q=&btnG=Search
So in your PHP:
if($_SERVER['REQUEST_METHOD'] == 'POST') {
classajaxValidate{
functionformValidate() {
//Put form elements into post variables (this is where you would sanitize your data)$field1 = $_POST['field1'];
$URL = $_POST['MenuURL'];
//Establish values that will be returned via ajax$return = array();
$return['msg'] = '';
$return['error'] = false;
//Begin form validation functionalityif (!isset($field1) || empty($field1)){
$return['error'] = true;
$return['msg'] .= '<li>Error: Field1 is empty.</li>';
}
//Begin form success functionalityif ($return['error'] === false){
$return['msg'] = '<li><iframe src="'.$URL . $field1.'" style="width:250px;height:250px;overflow:scroll;" id="MyFrame"></iframe></li>';
}
//Return json encoded resultsreturn json_encode($return);
}
}
$ajaxValidate = new ajaxValidate;
echo$ajaxValidate->formValidate();
exit;
}
In your markup and JS:
<ulid="info1"><li>Put anything in the field below.</li></ul><formid="form1"><inputtype="text"name="field1"id="field1"><inputtype="submit"name="submit"id="submit"value="Submit Form"></form><strong> Site <br/></strong><selectform="form1"id="MenuURL"><optionvalue="http://www.google.com/custom?btnG=Search&q=">Google</option><optionvalue="yahoo.com">Yahoo</option></select><script>
$('#form1').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'ajax.php',
data: {field1: $('#field1').val(), MenuURL: $('#MenuURL').val() },
dataType: 'JSON',
success: function (data) {
console.log(data);
$('#info1').html(data.msg);
}
});
});
</script>
Post a Comment for "Iframe With Variable Url In Php Variable"