कृपया मुझे मदद चाहिए मेरे पास एक इनपुट टेक्स्ट के साथ एक फॉर्म है
<?php
if($input == ‘aab’ or ‘aac’){
$action = " http://mywebsite.com /women/search=$input";
}else if($input == ‘aad’ or ‘aaf’ or ‘aat’){
$action =" http://mywebsite.com /men/search=$input”;
}
?>
<form action= "<?php echo $action; ?>" method="post">
<input id="Input" name="Input" class="input-block-level "></p>
<p class="pull-right" ><button id="Search" class="btn" > Search
</form>
इसकी दो अलग-अलग क्रियाएं हैं उदाहरण के लिए यदि इनपुट टेक्स्ट aab या aac से शुरू होता है तो यह http://mywebsite.comपर सबमिट हो जाएगा। a> /महिलाएं/खोज=$इनपुट और अगर इनपुट टेक्स्ट वैल्यू aad या aaf या aat एक्शन से शुरू होती है तो करने के लिए http://mywebsite.com /men/search=$input तो सबसे पहले हम जांच करेंगे कि इनपुट आब या एएसी या एड या एएटी से शुरू होता है या नहीं ... फिर सही यूआरएल पर सबिट करें
2 जवाब
पीएचपी के साथ यह संभव नहीं है। आप इसे जावास्क्रिप्ट की मदद से कर सकते हैं, मैं आपको jQuery का उपयोग करने का सुझाव दूंगा। नीचे जैसा कुछ।
<script type="text/javascript">
$(function(){
$('#Input').change(function(){
var input = $('#Input').val(),
status = input.substring(0,3);
if(status === "aad" || status === "aaf" || status === "aat"){
$('form').attr('action', 'http://mywebsite.com/men/search='+input);
}else if(status === "aab" || status === "aac"){
$('form').attr('action', 'http://mywebsite.com/women/search='+input);
}
});
});
</script>
Jquery को शामिल करना न भूलें।
आप वास्तव में किसके खिलाफ जांच कर रहे हैं, इसके लिए आपको $variable को प्रतिस्थापित करने की आवश्यकता है, लेकिन यह आप जो चाहते हैं उसके लिए काम करना चाहिए।
टिप्पणियों में कुछ नोट्स जोड़े, थोड़ा समझाने के लिए।
<?php
// Default action for if none is matched below in if/elseif clause
// by default, this will search the location you are not.
$action = '';
// Replace $variable with the variable you are checking against.
// The variable has to exist AND contain at least 3 characters
$input = isset($variable) && strlen($variable) > 3 ? substr($variable, 0, 3) : false;
// Check the $input variable is not false, and is either 'aab' or 'aac'
if ($input && in_array($input, array('aab', 'aac'))) {
$action = 'http://mywebsite.com/women/search=' . $input;
// Otherwise check if $input is set and is either: aad, aaf or aat
} else if ($input && in_array($input, array('aad', 'aaf', 'aat'))) {
$action = 'http://mywebsite.com/men/search=' . $input;
}
if (strlen($action)) {
echo <<<JS
<script>
document.location.href='$action';
</script>
JS;
exit;
}
// Output form. You were missing closing elements etc.
echo <<<FORM
<form action="" method="post">
<input id="Input" name="Input" class="input-block-level">
<p class="pull-right">
<button id="Search" class="btn" >Search</button>
</p>
</form>
FORM;
संबंधित सवाल
नए सवाल
php
PHP एक व्यापक रूप से उपयोग किया जाता है, उच्च-स्तरीय, गतिशील, वस्तु-उन्मुख, और व्याख्या की गई स्क्रिप्टिंग भाषा मुख्य रूप से सर्वर-साइड वेब विकास के लिए डिज़ाइन की गई है। PHP भाषा के बारे में सवालों के लिए इस्तेमाल किया।